Bug 1313960 - synchronous addon DB loader should handle in-progress async load r=kmag
authorRobert Helmer <rhelmer@mozilla.com>
Tue, 15 Nov 2016 13:40:47 -0800
changeset 367860 ca88bad072d09be6bd6229cf94465c93116c3beb
parent 367859 eae1056ae373b94d922c3a78cfaf72b3f80190b2
child 367861 91c099f8ec09b1fbf9b0159210f63a25f63d7208
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1313960
milestone53.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 1313960 - synchronous addon DB loader should handle in-progress async load r=kmag MozReview-Commit-ID: LwzmRr3PdXx
toolkit/mozapps/extensions/internal/XPIProviderUtils.js
--- a/toolkit/mozapps/extensions/internal/XPIProviderUtils.js
+++ b/toolkit/mozapps/extensions/internal/XPIProviderUtils.js
@@ -614,24 +614,21 @@ this.XPIDatabase = {
       else {
         this.rebuildUnreadableDB(e, aRebuildOnError);
       }
     }
     finally {
       if (fstream)
         fstream.close();
     }
-    // If an async load was also in progress, resolve that promise with our DB;
-    // otherwise create a resolved promise
+    // If an async load was also in progress, record in telemetry.
     if (this._dbPromise) {
       AddonManagerPrivate.recordSimpleMeasure("XPIDB_overlapped_load", 1);
-      this._dbPromise.resolve(this.addonDB);
     }
-    else
-      this._dbPromise = Promise.resolve(this.addonDB);
+    this._dbPromise = Promise.resolve(this.addonDB);
   },
 
   /**
    * Parse loaded data, reconstructing the database if the loaded data is not valid
    * @param aRebuildOnError
    *        If true, synchronously reconstruct the database from installed add-ons
    */
   parseDB: function(aData, aRebuildOnError) {
@@ -765,31 +762,32 @@ this.XPIDatabase = {
     let readOptions = {
       outExecutionDuration: 0
     };
     return this._dbPromise = OS.File.read(this.jsonFile.path, null, readOptions).then(
       byteArray => {
         logger.debug("Async JSON file read took " + readOptions.outExecutionDuration + " MS");
         AddonManagerPrivate.recordSimpleMeasure("XPIDB_asyncRead_MS",
           readOptions.outExecutionDuration);
-        if (this._addonDB) {
+
+        if (this.addonDB) {
           logger.debug("Synchronous load completed while waiting for async load");
           return this.addonDB;
         }
         logger.debug("Finished async read of XPI database, parsing...");
         let decodeTimer = AddonManagerPrivate.simpleTimer("XPIDB_decode_MS");
         let decoder = new TextDecoder();
         let data = decoder.decode(byteArray);
         decodeTimer.done();
         this.parseDB(data, true);
         return this.addonDB;
       })
-    .then(null,
+    .catch(
       error => {
-        if (this._addonDB) {
+        if (this.addonDB) {
           logger.debug("Synchronous load completed while waiting for async load");
           return this.addonDB;
         }
         if (error.becauseNoSuchFile) {
           this.upgradeDB(true);
         }
         else {
           // it's there but unreadable