Skip to content
Snippets Groups Projects
Commit 322d3414 authored by Gijs Kruitbosch's avatar Gijs Kruitbosch
Browse files

Bug 1795687 - disallow opening content prefs in shutdown, r=mak

This prevents the issue described in the bug in two ways:
- avoid attempting to start a connection in shutdown
- call connection.close() even if we fail to add a shutdown blocker.

It does both because if we did only the first, we would still have a potential race where
when _getConnection is called, we would not be in shutdown, but by the time
we try to close the connection, we could be. If we only did the second, we'd keep retrying
which is also bad.

Differential Revision: https://phabricator.services.mozilla.com/D163225
parent af4d718e
No related branches found
No related tags found
No related merge requests found
......@@ -1159,6 +1159,13 @@ ContentPrefService2.prototype = {
},
async _getConnection(aAttemptNum = 0) {
if (
Services.startup.isInOrBeyondShutdownPhase(
Ci.nsIAppStartup.SHUTDOWN_PHASE_APPSHUTDOWN
)
) {
throw new Error("Can't open content prefs, we're in shutdown.");
}
let path = PathUtils.join(PathUtils.profileDir, "content-prefs.sqlite");
let conn;
let resetAndRetry = async e => {
......@@ -1184,10 +1191,21 @@ ContentPrefService2.prototype = {
};
try {
conn = await lazy.Sqlite.openConnection({ path });
lazy.Sqlite.shutdown.addBlocker(
"Closing ContentPrefService2 connection.",
() => conn.close()
);
try {
lazy.Sqlite.shutdown.addBlocker(
"Closing ContentPrefService2 connection.",
() => conn.close()
);
} catch (ex) {
// Uh oh, we failed to add a shutdown blocker. Close the connection
// anyway, but make sure that doesn't throw.
try {
await conn?.close();
} catch (ex) {
console.error(ex);
}
return null;
}
} catch (e) {
Cu.reportError(e);
return resetAndRetry(e);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment