From 04650d926fb8a167d09ff211e8641a9e357aeb87 Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Fri, 6 Oct 2023 20:57:58 +0000 Subject: [PATCH] Bug 1856087 - Bypass assertion if NS_DISPATCH_IGNORE_BLOCK_DISPATCH is set, r=xpcom-reviewers,jstutte The `gXPCOMThreadsShutDownNotified` assertion exists to discourage dispatching to a background thread after xpcom-shutdown-threads. This unfortunately poorly interacts with the nsThreadPool implementation. We use nsThreadPools all of the way until threads are fully shut down during ShutdownNonMainThreads, and they dispatch a runnable to a background thread when starting a new thread. This patch disables the assertion when NS_DISPATCH_IGNORE_BLOCK_DISPATCH is specified. This flag already effectively indicates "trust me I am dispatching to a thread which is in a weird state, this dispatch must succeed", so seems appropriate to use in this situation, and will avoid the underlying issue. The nsThreadPool runnable is already dispatched with this flag set. Differential Revision: https://phabricator.services.mozilla.com/D190303 --- xpcom/threads/ThreadEventTarget.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xpcom/threads/ThreadEventTarget.cpp b/xpcom/threads/ThreadEventTarget.cpp index d5df2efda12d..17844d488687 100644 --- a/xpcom/threads/ThreadEventTarget.cpp +++ b/xpcom/threads/ThreadEventTarget.cpp @@ -73,7 +73,8 @@ ThreadEventTarget::Dispatch(already_AddRefed aEvent, } NS_ASSERTION(!gXPCOMThreadsShutDownNotified || mIsMainThread || - PR_GetCurrentThread() == mThread, + PR_GetCurrentThread() == mThread || + (aFlags & NS_DISPATCH_IGNORE_BLOCK_DISPATCH), "Dispatch to non-main thread after xpcom-shutdown-threads"); if (mBlockDispatch && !(aFlags & NS_DISPATCH_IGNORE_BLOCK_DISPATCH)) {