title: Google Apps script setValues() issue: timing out intermittently
body: <p>I have a Google Apps script that has been running without issues for 4 years. However, since 3 weeks I have this problem: the script is running for a very long time and failing. This happens every 3 out of 10 runs. The error message is <em>“Service Spreadsheets timed out while accessing spreadsheet with id [spreadsheet id here]”</em>.</p>
  <p>The actual script, which is elaborate (thousands of lines) and runs on hundreds of spreadsheets takes the data using <code>fetchUrl()</code> and populates the sheet with <code>setValues()</code>. This actual script used to work fine on spreadsheets with 10 sheets and could update the 180k cells in each sheet without a problem for the past 4 years. Now, I can't update even one sheet.</p>
  <p>The script below replicates this issue: it copies 1300 rows by 140 columns from Sheet1 to Sheet2 using <code>.getValues()</code> and <code>.setValues()</code>.The script starts to fail when the number of rows is increased above 800. When it runs fine the execution logs show it takes 8 seconds. When it fails the logs show run times of up to 900 seconds. During that time, you can’t access the spreadsheet for more than 10 minutes, if you try to load the spreadsheet in a different tab it doesn’t load at all.</p>
  <p>I have opened an issue with Google Support, I got no timeline, but profuse apologies for the inconvenience. This happens on all domains I have tried the script on, not only mine. You need to try running the script 10 times to see the failures.</p>
  <p>I would greatly appreciate if someone could suggest a workaround or provide some insight about this issue.</p>
  <p>Here is the link to the spreadsheet replicating the issue: <a href="https://docs.google.com/spreadsheets/d/1jea15rtjv85YIZumABMfFKESb2_QmX0-7zC-KchWeDc/edit?usp=sharing" rel="noreferrer">https://docs.google.com/spreadsheets/d/1jea15rtjv85YIZumABMfFKESb2_QmX0-7zC-KchWeDc/edit?usp=sharing</a></p>
  <pre><code>function myFunction() {
    var row1 = 1;
    var col1 = 1;
    var row2 = 1300;
    var col2 = 140;
    console.log({numrows:row2, numcols:col2} );
    var rng = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(&quot;Sheet1&quot;).getRange(row1,col1,row2,col2);
    var values_to_set = rng.getValues();
    var rng2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(&quot;Sheet2&quot;).getRange(row1,col1,row2,col2);
    rng2.setValues(values_to_set);
    console.log('done');
    
  }
  </code></pre>