Bug 888784 - Use Sqlite.shutdown instead of AsyncShutdown to close FormHistory database connection. r?mak
MozReview-Commit-ID: GsM0bf8V7XD
--- 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);