From 4b7e77481755e74dcbe913fb9f0f366ac7d62e64 Mon Sep 17 00:00:00 2001 From: Jens Stutte Date: Thu, 12 May 2022 16:13:28 +0000 Subject: [PATCH] Bug 1767214: Avoid executing WorkerMainThreadRunnable::Run late in shutdown. r=dom-worker-reviewers,jesup Differential Revision: https://phabricator.services.mozilla.com/D145577 --- dom/workers/WorkerRunnable.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dom/workers/WorkerRunnable.cpp b/dom/workers/WorkerRunnable.cpp index 3ba00ff0791d..4e0b8bc66706 100644 --- a/dom/workers/WorkerRunnable.cpp +++ b/dom/workers/WorkerRunnable.cpp @@ -11,6 +11,7 @@ #include "jsapi.h" #include "jsfriendapi.h" #include "mozilla/AlreadyAddRefed.h" +#include "mozilla/AppShutdown.h" #include "mozilla/Assertions.h" #include "mozilla/DebugOnly.h" #include "mozilla/ErrorResult.h" @@ -584,6 +585,12 @@ NS_IMETHODIMP WorkerMainThreadRunnable::Run() { AssertIsOnMainThread(); + // This shouldn't be necessary once we're better about making sure no workers + // are created during shutdown in earlier phases. + if (AppShutdown::IsInOrBeyond(ShutdownPhase::XPCOMShutdownThreads)) { + return NS_ERROR_ILLEGAL_DURING_SHUTDOWN; + } + bool runResult = MainThreadRun(); RefPtr response =