Bug 1735284: Add a check in nsThread::ShutdownInternal if the shutdown event could be dispatched. r=xpcom-reviewers,nika
authorJens Stutte <jstutte@mozilla.com>
Thu, 21 Oct 2021 11:51:09 +0000
changeset 596569 66532c42429039aa123017d761dfb4f0f55fcb90
parent 596568 3748f5bdcf1136e84116bb28690cef6c19c345ec
child 596570 57e3d6fb9559aef5b61398a1688a0af58725e077
push id38901
push usersmolnar@mozilla.com
push dateThu, 21 Oct 2021 16:02:15 +0000
treeherdermozilla-central@aceba6246b0e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxpcom-reviewers, nika
bugs1735284
milestone95.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 1735284: Add a check in nsThread::ShutdownInternal if the shutdown event could be dispatched. r=xpcom-reviewers,nika Differential Revision: https://phabricator.services.mozilla.com/D128167
xpcom/threads/nsThread.cpp
--- a/xpcom/threads/nsThread.cpp
+++ b/xpcom/threads/nsThread.cpp
@@ -787,18 +787,23 @@ nsThreadShutdownContext* nsThread::Shutd
   auto context =
       new nsThreadShutdownContext(WrapNotNull(this), currentThread, aSync);
   Unused << *currentThread->mRequestedShutdownContexts.EmplaceBack(context);
 
   // Set mShutdownContext and wake up the thread in case it is waiting for
   // events to process.
   nsCOMPtr<nsIRunnable> event =
       new nsThreadShutdownEvent(WrapNotNull(this), WrapNotNull(context));
-  // XXXroc What if posting the event fails due to OOM?
-  mEvents->PutEvent(event.forget(), EventQueuePriority::Normal);
+  if (!mEvents->PutEvent(event.forget(), EventQueuePriority::Normal)) {
+    // We do not expect this to happen. Let's collect some diagnostics.
+    nsAutoCString threadName;
+    currentThread->GetThreadName(threadName);
+    MOZ_CRASH_UNSAFE_PRINTF("Attempt to shutdown an already dead thread: %s",
+                            threadName.get());
+  }
 
   // We could still end up with other events being added after the shutdown
   // task, but that's okay because we process pending events in ThreadFunc
   // after setting mShutdownContext just before exiting.
   return context;
 }
 
 void nsThread::ShutdownComplete(NotNull<nsThreadShutdownContext*> aContext) {