How to fix "There are too many LockService operations against the same script" error?

how to fix anything
how to fix phone
how to fix broken things
how to fix everything book
how to fix a zipper
how to fix things around the house
how to fix stuff
how to repair appliances

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.

  • Is there a limit to the number of LockService operations per user or per script?
  • If so, what is the limit?

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.

How to Fix ANYTHING, Timestamps 00:01 Slime cleaning trick 02:29 Coca-cola rust removal 02:55 Wall repair trick 03 Duration: 13:56 Posted: Apr 21, 2020 Thousands of repair manuals, tutorials, and how-to guides for DIY fixes. From electronics to cars, learn how to repair your own stuff and save yourself some money.

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.

How To Repair Almost Everything, How to Fix (Just About) Everything: More Than 550 Step-by-Step Instructions for Everything from Fixing a Faucet to Removing Mystery Stains to Curing a� Here's how: 1. Navigate to the Windows 10 Advanced Startup Options menu. On many laptops, hitting F11 as soon as you power on will 2. Click Startup Repair.

I don't know the answer to the question (so I won't mark this answer as accepted), but here is my workaround.

Not the most elegant solution as it does not protect against all cases (triggers running in quick succession and triggers at times running out of sequence), so any guidance from the more experienced is appreciated.

try{

  for(var i=1; i<11; i++){ //attempt 10 times, then run and hope for the best
    var documentLock = PropertiesService.getDocumentProperties().getProperty('documentLock');
    if(documentLock){
    Utilities.sleep(20000); //if locked, sleep for 20 seconds
    console.log('Wait ' + i + ' for documentLock to be released.');
    }else{break;}
  }

  PropertiesService.getDocumentProperties().setProperty('documentLock', true);

  runSomeFunction()

}
catch(err){

  console.error(err);
  console.error(err["stack"]);

}
finally{

  PropertiesService.getDocumentProperties().deleteProperty('documentLock');

}

How to Fix (Just About) Everything: More Than 550 Step-by-Step , Dropped that ancient vase your great grandfather shipped from the Middle East in the 19th century? Happens. But it might not be trash just yet, as these creative � iFixit is a global community of people helping each other repair things. Let's fix the world, one device at a time. Troubleshoot with experts in the Answers forum—and build your own how-to guides to share with the world.

40 Most Creative Examples Of How To Fix Broken Stuff, Klayman explains, “A key principle of future-focused feedback is to avoid talking about why things went wrong in the past. This runs counter to� People Helping People Fix Stuff. Help is here! Learn how to do your own repairs and save money! This site is filled with articles written by skilled individuals. You will find step by step "How To", tips and tricks, and general guidance on fixing your stuff. Finding Solutions

Your Performance Feedback Doesn't Work—Here's How To Fix It, Learn how to fix your broken appliance yourself, no repairman needed. Select the appliance that is giving you trouble and you'll find information on the common � Easy Fix solutions have been discontinued. Instead, you can upgrade to Windows 10 and get troubleshooters that are built right in. To get Windows 10, see Windows 10 Home. Need more info on Windows 10? See Upgrade to Windows 10: FAQ. Windows 10. Windows 10 uses troubleshooters to help you solve problems with your PC. To run a troubleshooter:

How To Fix A Broken Appliance, This educator's guide provides articles, videos & other resources to aid in teaching about tools, common home repair projects and vocabulary to students. How to Fix the Most Annoying Things in Windows 10. Windows 10 is great, but it has its issues, from unpredictable reboots to Cortana. Here's how to fix some of the more irritating quirks with

Comments
  • Seems like a bug of Google App Script, which has been solved by Google in Nov 2019.
  • Thanks Amit, very strange that it would related to triggers but I'll give it a go and see if it improves.
  • I had two triggers per user which I scaled back to one per user overnight and unfortunately continue to see this error in full force. It appears there is an unadvertised limit on the number of locks per script. I have temporarily amended it from a Document Lock to a Script Lock. Not ideal, but it should solve it temporarily until I find an alternate method.
  • I' m experencing the same problem with ScriptLock, sporadically though.