I have a public add-on that utilises Google Apps Script Lock Service to prevent reading a spreadsheet before writes are made.
var lock = LockService.getDocumentLock();
var success = lock.tryLock(240000); // 4 minutes
if (!success) {
console.warn('Could not obtain lock after 4 minutes.');
return;
}
//perform some function then release lock
lock.releaseLock();
I continue to receive the error message:
There are too many LockService operations against the same script.
Originally I thought this error was 'user based' and there was potentially a quota against the number of Lock Service operations per user, however I recently started seeing it appear more often against 30+ users in the past few days.
I don't see any reference to a quota within Google Apps Script quotas
Nor do I see any reference to a quota within the LockService documentation
There is a report about this: https://issuetracker.google.com/issues/112384851
It appears this might happen sporadically. A Google employee responded with the following:
Just to give an update to this: The Apps Script team recommends:
1) Use a try/catch block around the LockService call, and assume that an error means "lock was not acquired" (whatever that means for the logic the script is trying to do).
2) If "lock was not acquired" means "script should try again", then put a sleep in there of a few seconds (maybe even exponential backoff) before retrying the LockService operation.
We do not have any other solution for this at the moment and might have an update once certain changes are made to Apps Script.
This likely happens when there are multiple triggers trying to access the same Google Sheet simultaneously. Google Quota page doesn't document the exact limits anywhere but try reducing the number of triggers associated with the sheet and it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With