Bug 1501196 - Ensure RuntimeService::Shutdown() is always called. r=baku

It's possible for RuntimeService to be created after 'xpcom-shutdown' has fired. In this case, it
will receive 'xpcom-shutdown-threads' and perform Cleanup() but not Shutdown(). This means that
mShuttingDown will not be set to 'true', but mIdleThreadTimer will be destroyed. This can cause
crashes if a NoteIdleThread callback runs after Cleanup(). This has been observed to happen in
xpcshell tests.

I think the easiest way to handle this is to manually call Shutdown() in Cleanup() when we
see that mShuttingDown == false. This means that Shutdown() might be called in GetOrCreateService()
if we fail to create the service, but it looks like the code can handle this.

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

--HG--
extra : rebase_source : 3c4a9cb76b81c4aef87b6373548e9da8ca64075e
extra : amend_source : d17d7a0e35e8bd9fcfbbd567e387d9af857bfd8a
This commit is contained in:
Ryan Hunt 2018-10-30 11:51:12 -05:00
parent 0b6d8f10c9
commit 76554e50cb

View File

@ -2026,6 +2026,10 @@ RuntimeService::Cleanup()
{
AssertIsOnMainThread();
if (!mShuttingDown) {
Shutdown();
}
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
NS_WARNING_ASSERTION(obs, "Failed to get observer service?!");