diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 6b2b93a1fb54..4bee876a1959 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -3526,9 +3526,15 @@ WorkerPrivate::GetClientState() const } const Maybe -WorkerPrivate::GetController() const +WorkerPrivate::GetController() { AssertIsOnWorkerThread(); + { + MutexAutoLock lock(mMutex); + if (mStatus >= Terminating) { + return Maybe(); + } + } MOZ_DIAGNOSTIC_ASSERT(mClientSource); return mClientSource->GetController(); } @@ -3537,9 +3543,15 @@ void WorkerPrivate::Control(const ServiceWorkerDescriptor& aServiceWorker) { AssertIsOnWorkerThread(); - MOZ_DIAGNOSTIC_ASSERT(mClientSource); MOZ_DIAGNOSTIC_ASSERT(!IsChromeWorker()); MOZ_DIAGNOSTIC_ASSERT(Type() != WorkerTypeService); + { + MutexAutoLock lock(mMutex); + if (mStatus >= Terminating) { + return; + } + } + MOZ_DIAGNOSTIC_ASSERT(mClientSource); mClientSource->SetController(aServiceWorker); } diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index d693fccbd5e2..90c10c1e423b 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -560,7 +560,7 @@ public: GetClientState() const; const Maybe - GetController() const; + GetController(); void Control(const ServiceWorkerDescriptor& aServiceWorker);