Bug 1334165 Don't allow event dispatch after WebSocket allows worker thread to exit cleanly. r=baku a=jcristau
authorBen Kelly <ben@wanderview.com>
Fri, 27 Jan 2017 06:06:33 -0800
changeset 366753 4271550cd0b402cfb44cc0bc4312338582a7418f
parent 366752 e2be2a6d8c057ac80953e25244df94378878ed28
child 366754 0e5fcab28382aa0dc2db37f34b30e51fc610cbc6
push id6839
push usercbook@mozilla.com
push dateMon, 30 Jan 2017 14:41:09 +0000
treeherdermozilla-beta@0f54c5ef73d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, jcristau
bugs1334165
milestone52.0
Bug 1334165 Don't allow event dispatch after WebSocket allows worker thread to exit cleanly. r=baku a=jcristau
dom/base/WebSocket.cpp
--- a/dom/base/WebSocket.cpp
+++ b/dom/base/WebSocket.cpp
@@ -2292,16 +2292,21 @@ WebSocketImpl::RegisterWorkerHolder()
 void
 WebSocketImpl::UnregisterWorkerHolder()
 {
   MOZ_ASSERT(mDisconnectingOrDisconnected);
   MOZ_ASSERT(mWorkerPrivate);
   mWorkerPrivate->AssertIsOnWorkerThread();
   MOZ_ASSERT(mWorkerHolder);
 
+  {
+    MutexAutoLock lock(mMutex);
+    mWorkerShuttingDown = true;
+  }
+
   // The DTOR of this WorkerHolder will release the worker for us.
   mWorkerHolder = nullptr;
 
   mWorkerPrivate = nullptr;
 
 #ifdef DEBUG
   SetHasWorkerHolderRegistered(false);
 #endif
@@ -2846,17 +2851,17 @@ WebSocketImpl::Dispatch(already_AddRefed
     return NS_DispatchToMainThread(event_ref.forget());
   }
 
   MutexAutoLock lock(mMutex);
   if (mWorkerShuttingDown) {
     return NS_OK;
   }
 
-  MOZ_ASSERT(mWorkerPrivate);
+  MOZ_DIAGNOSTIC_ASSERT(mWorkerPrivate);
 
 #ifdef DEBUG
   MOZ_ASSERT(HasWorkerHolderRegistered());
 #endif
 
   // If the target is a worker, we have to use a custom WorkerRunnableDispatcher
   // runnable.
   RefPtr<WorkerRunnableDispatcher> event =