'Trigger error: We're sorry, a server error occurred while reading from storage. Error code PERMISSION_DENIED

My Gapps script called from time based trigger is logging tons of errors "We're sorry, a server error occurred while reading from storage. Error code PERMISSION_DENIED". I assume there are users, who installed the app and trigger, but later removed permissions for script to run. Which, obviously, may cause this issue. I'm still trying and failing to avoid it...

This is how trigger is installed:

var triggerFunction = "processRecurrentLists";  //trigger callback function name

//---------------------------------------------
function createTriggers(tmz) {
  // Trigger running at 1am depending on timezone specified in settings
  // If no timezone specified, script timezone is used (GMT)
  ScriptApp.newTrigger(triggerFunction)
      .timeBased()
      .everyDays(1)
      .inTimezone(tmz)
      .atHour(1)
      .create();
      
}

This is the triggered function:

function processRecurrentLists() {
  // Check if the actions of the trigger requires authorization that has not
  // been granted yet; if not, then end - nothing to do.
  if (!isScriptAuthorized()) {
    console.warn("RecGTasks script is not authorized to run. Please, authorize first.");
    return;
  }

  // ... more code here
}

And function testing authorization:

function isScriptAuthorized() {
  try {
    var authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);
    return (authInfo.getAuthorizationStatus() == ScriptApp.AuthorizationStatus.NOT_REQUIRED);
  } catch (e) {
    console.warn("Script not authorized. err=%s",e.message);
    return false;
  }
}

My assumption is that function isScriptAuthorized returns false if script is not authorized and script ends gracefully, but it seems not to be the case...

Any idea on this?

Update 1 I have made script accessible for all users as a workaround for https://issuetracker.google.com/issues/175139769 and on the same day message changed to "Authorization is required to perform that action.", so no more PERMISSION_DENIED. Investigating further.

Update 2 Yes, as @ziganotschka pointed out, it is related to V8. I used following script to test it thoroughly:

function doGet() {
  // if trigger not installed
  if (ScriptApp
      .getProjectTriggers()
      .filter(function(t){return t.getHandlerFunction() === "myFunction"})
      .length == 0
     ){
    // create trigger firing every 1min
    ScriptApp.newTrigger("myFunction")
    .timeBased()
    .everyMinutes(1)
    .create();      
  }
  return HtmlService.createHtmlOutput('<h1>Trigger test installed</h1>');
}

function myFunction() { 
  Logger.log("Hello from triggered function");
  return ("Hello from server");
}


Solution 1:[1]

It seems to be a bug related to the v8 runtime

Have a look here and here.

This problem seems to occur when users are signed in with multiple accounts at once.

While Google is fixing the bug, I suggest you to temprorily disable the v8 runtime to avoid the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ziganotschka