I have a Looker Studio custom connector written in Google Apps Script. In the connector, I am using the LockService's tryLock(), hasLock(), and releaseLock() functions to prevent concurrent execution of a section of code. Most of the time it works fine, but sometimes I get an error like this:
Exception: We're sorry, a server error occurred. Please wait a bit and try again.
The stack trace shows that the error always comes on the lines where the lock functions are called.
I am initializing the lock globally like this:
var lock = LockService.getScriptLock();
and then using the functions like this:
function execute(request) {
try {
lock.tryLock(100);
if(lock.hasLock()) {
// custom code
lock.releaseLock();
}
}
catch(e) {
console.error(e)
}
finally {
if(lock.hasLock()) {
lock.releaseLock();
}
}
}
Exception: We're sorry, a server error occurred. Please wait a bit and try again. at Code:308 (responseToRows) at Code:435 (getData)