Bug 1334165 Don't allow event dispatch after WebSocket allows worker thread to exit cleanly. r=baku
authorBen Kelly <ben@wanderview.com>
Fri, 27 Jan 2017 06:06:33 -0800
changeset 331410 3267ca391018b774910ca4e58120ef23e75dffdd
parent 331409 53fee347291be48970617f64d4a2194e95152180
child 331411 12261233a2a5cee3f65ef38877034389c343ee18
push id86240
push userbkelly@mozilla.com
push dateFri, 27 Jan 2017 14:06:38 +0000
treeherdermozilla-inbound@3267ca391018 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1334165
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1334165 Don't allow event dispatch after WebSocket allows worker thread to exit cleanly. r=baku
dom/base/WebSocket.cpp
--- a/dom/base/WebSocket.cpp
+++ b/dom/base/WebSocket.cpp
@@ -2274,16 +2274,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
@@ -2828,17 +2833,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 =