Bug 888784 - Use Sqlite.shutdown instead of AsyncShutdown to close FormHistory database connection. r?mak draft
authorMike Conley <mconley@mozilla.com>
Tue, 09 Jan 2018 15:47:49 -0500
changeset 723120 93083f577f645a2c2921030be91e0e5471a80126
parent 723119 68ac9fc8a26b9adfc00abb09adbefaa2e957dd3b
child 723121 2efb0ecf250ff79f3b462fb73a066cdd0e956a71
push id96341
push usermconley@mozilla.com
push dateMon, 22 Jan 2018 16:46:17 +0000
reviewersmak
bugs888784
milestone60.0a1
Bug 888784 - Use Sqlite.shutdown instead of AsyncShutdown to close FormHistory database connection. r?mak MozReview-Commit-ID: GsM0bf8V7XD
toolkit/components/satchel/FormHistory.jsm
--- a/toolkit/components/satchel/FormHistory.jsm
+++ b/toolkit/components/satchel/FormHistory.jsm
@@ -634,24 +634,21 @@ this.DB = {
    *           with the Sqlite.jsm error.
    */
   get conn() {
     delete this.conn;
     let conn = new Promise(async (resolve, reject) => {
       try {
         this._instance = await this._establishConn();
       } catch (e) {
-        log("Failed to establish database connection.");
+        log("Failed to establish database connection: " + e);
         reject(e);
         return;
       }
 
-      AsyncShutdown.profileBeforeChange.addBlocker(
-        "Closing FormHistory database.", () => this._instance.close());
-
       resolve(this._instance);
     });
 
     return this.conn = conn;
   },
 
   // Private functions
 
@@ -671,16 +668,18 @@ this.DB = {
    * @rejects  After MAX_ATTEMPTS, this will reject with the Sqlite.jsm
    *           error.
    */
   async _establishConn(attemptNum = 0) {
     log(`Establishing database connection - attempt # ${attemptNum}`);
     let conn;
     try {
       conn = await Sqlite.openConnection({ path: this.path });
+      Sqlite.shutdown.addBlocker(
+        "Closing FormHistory database.", () => conn.close());
     } catch (e) {
       // Bug 1423729 - We should check the reason for the connection failure,
       // in case this is due to the disk being full or the database file being
       // inaccessible due to third-party software (like anti-virus software).
       // In that case, we should probably fail right away.
       if (attemptNum < this.MAX_ATTEMPTS) {
         log("Establishing connection failed.");
         await this._failover(conn);