Bug 1616186 - Don't try to write StartupCache if it doesn't exist r=froydnj

The exact circumstances of how this is showing up in the wild aren't
clear - there seem to be a couple of ways we can get here. However it
all revolves around early shutdowns (i.e., from the select profile popup)
- before the StartupCache is ever initialized. In any case, the solution
shouldn't change based on the exact circumstances - if we don't have a
StartupCache, there's no need to write one. Also, don't bother lazy
initializing it if it doesn't exist yet.

Differential Revision: https://phabricator.services.mozilla.com/D63208

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Doug Thayer 2020-02-18 17:49:47 +00:00
parent 2397c625f5
commit 3f9b0177d2
3 changed files with 10 additions and 1 deletions

View File

@ -102,6 +102,10 @@ static nsresult MapLZ4ErrorToNsresult(size_t aError) {
return NS_ERROR_FAILURE;
}
StartupCache* StartupCache::GetSingletonNoInit() {
return StartupCache::gStartupCache;
}
StartupCache* StartupCache::GetSingleton() {
if (!gStartupCache) {
if (!XRE_IsParentProcess()) {

View File

@ -175,6 +175,7 @@ class StartupCache : public nsIMemoryReporter {
nsresult GetDebugObjectOutputStream(nsIObjectOutputStream* aStream,
nsIObjectOutputStream** outStream);
static StartupCache* GetSingletonNoInit();
static StartupCache* GetSingleton();
static void DeleteSingleton();

View File

@ -127,7 +127,11 @@ void AppShutdown::Init(AppShutdownMode aMode) {
StaticPrefs::toolkit_shutdown_lateWriteChecksStage();
sLateWriteChecksPhase = GetShutdownPhaseFromPrefValue(lateWriteChecksPref);
scache::StartupCache::GetSingleton()->MaybeInitShutdownWrite();
// Very early shutdowns can happen before the startup cache is even
// initialized; don't bother initializing it during shutdown.
if (auto* cache = scache::StartupCache::GetSingletonNoInit()) {
cache->MaybeInitShutdownWrite();
}
}
void AppShutdown::MaybeFastShutdown(ShutdownPhase aPhase) {