Bug 1251347 - Refining SessionFile Shutdown hang details;r=me
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Fri, 26 Feb 2016 11:11:47 +0100
changeset 322259 cc6dd36ae9082f827e583dbd0543d88b610f954f
parent 322258 debf6c7316b7a0514dbf2c85bb7df4b4a40d5972
child 322260 bc6e8eb75949f36b116abceb33e3281d675396b5
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1251347
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1251347 - Refining SessionFile Shutdown hang details;r=me MozReview-Commit-ID: Jag5oFwKTqr
browser/components/sessionstore/SessionFile.jsm
--- a/browser/components/sessionstore/SessionFile.jsm
+++ b/browser/components/sessionstore/SessionFile.jsm
@@ -172,19 +172,29 @@ var SessionFileInternal = {
       if (SessionFileInternal.latestUpgradeBackupID) {
         // We have an upgradeBackup
         order.push("upgradeBackup");
       }
       return order;
     },
   }),
 
-  // `true` once `write` has succeeded at last once.
-  // Used for error-reporting.
-  _hasWriteEverSucceeded: false,
+  // Number of attempted calls to `write`.
+  // Note that we may have _attempts > _successes + _failures,
+  // if attempts never complete.
+  // Used for error reporting.
+  _attempts: 0,
+
+  // Number of successful calls to `write`.
+  // Used for error reporting.
+  _successes: 0,
+
+  // Number of failed calls to `write`.
+  // Used for error reporting.
+  _failures: 0,
 
   // Resolved once initialization is complete.
   // The promise never rejects.
   _deferredInitialized: PromiseUtils.defer(),
 
   // The ID of the latest version of Gecko for which we have an upgrade backup
   // or |undefined| if no upgrade backup was ever written.
   get latestUpgradeBackupID() {
@@ -283,47 +293,51 @@ var SessionFileInternal = {
       // write instructions.
       isFinalWrite = true;
       RunState.setClosed();
     }
 
     let performShutdownCleanup = isFinalWrite &&
       !sessionStartup.isAutomaticRestoreEnabled();
 
+    this._attempts++;
     let options = {isFinalWrite, performShutdownCleanup};
     let promise = this._deferredInitialized.promise.then(() => SessionWorker.post("write", [aData, options]));
 
     // Wait until the write is done.
     promise = promise.then(msg => {
       // Record how long the write took.
       this._recordTelemetry(msg.telemetry);
-      this._hasWriteEverSucceeded = true;
+      this._successes++;
       if (msg.result.upgradeBackup) {
         // We have just completed a backup-on-upgrade, store the information
         // in preferences.
         Services.prefs.setCharPref(PREF_UPGRADE_BACKUP,
           Services.appinfo.platformBuildID);
       }
     }, err => {
       // Catch and report any errors.
       console.error("Could not write session state file ", err, err.stack);
+      this._failures++;
       // By not doing anything special here we ensure that |promise| cannot
       // be rejected anymore. The shutdown/cleanup code at the end of the
       // function will thus always be executed.
     });
 
     // Ensure that we can write sessionstore.js cleanly before the profile
     // becomes unaccessible.
     AsyncShutdown.profileBeforeChange.addBlocker(
       "SessionFile: Finish writing Session Restore data",
       promise,
       {
         fetchState: () => ({
           options,
-          hasEverSucceeded: this._hasWriteEverSucceeded
+          attempts: this._attempts,
+          successes: this._successes,
+          failures: this._failures,
         })
       });
 
     // This code will always be executed because |promise| can't fail anymore.
     // We ensured that by having a reject handler that reports the failure but
     // doesn't forward the rejection.
     return promise.then(() => {
       // Remove the blocker, no matter if writing failed or not.