Closed Bug 1764119 Opened 2 years ago Closed 2 years ago

Don't run XPCOMShutdownFinal before nsThreadManager::Shutdown has shut down threads & run shutdown tasks

Categories

(Core :: XPCOM, task)

task

Tracking

()

RESOLVED FIXED
102 Branch
Tracking Status
firefox101 --- fixed
firefox102 --- fixed

People

(Reporter: nika, Assigned: nika)

References

Details

Attachments

(2 files)

In bug 1637890, XPCOM shutdown was adjusted so that KillClearOnShutdown(XPCOMShutdownFinal) was fired before nsThreadManager::Shutdown(), in order to allow additional events to be processed on the main thread from ClearOnShutdown-ed static destructors. Types which require this behaviour should probably be moved back to a different phase, such as XPCOMShutdownLoaders or XPCOMShutdownThreads, and the final shutdown phase should be moved back to happening after we've shut down threads fully.

Due to this change having existed for a while, we may need to keep the main thread accepting events for XPCOMShutdownFinal, however we are already blocking new event dispatches to background threads at that point, so we can probably shut down background threads & run shutdown callbacks.

See Also: → 1764251
Blocks: 1764181
See Also: → 1738104

This patch moves where we perform the final KillClearOnShutdown to occur
after we've shut down non-main threads, but before the main thread stops
accepting events. This should help ensure that unsuspecting events,
including those triggered from nsIThreadShutdownTask tasks, don't run
after KillClearOnShutdown has been run on background or main threads.

This KillClearOnShutdown was moved to occur before
nsThreadManager::Shutdown() in bug 1637890, as there were examples of
KillClearOnShutdown callbacks which needed to be able to dispatch
main-thread runnables. This change should not regress that use-case, as
we are still accepting new events on the main thread after the callback.

Non-main threads were already unreliable after this call as we already
block normal dispatches by setting gXPCOMThreadsShutdown, and new
threads cannot be started for the background thread pool.

We already have a mechanism for ending threads accepting new messages
when they are shut down, so this only allows tasks started from thread
shutdown tasks during xpcom shutdown to behave consistently.

We already didn't prevent dispatching to the background thread pool at
this time, so it should make little difference there as well, and may
just instead save us from deadlocks where code expects a dispatch to
succeed and it does not during actor shutdown.

Depends on D144591

Pushed by nlayzell@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/f8ba6b0a8c6f
Part 1: Do final KillClearOnShutdown after XPCOM threads shutdown, r=xpcom-reviewers,kmag,jstutte
https://hg.mozilla.org/integration/autoland/rev/62743521627e
Part 2: Don't check gXPCOMThreadsShutdown in ThreadEventTarget::Dispatch, r=xpcom-reviewers,kmag,jstutte
Pushed by nlayzell@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/53c35279a526
Part 1: Do final KillClearOnShutdown after XPCOM threads shutdown, r=xpcom-reviewers,kmag,jstutte
https://hg.mozilla.org/integration/autoland/rev/4117dd5eaf86
Part 2: Don't check gXPCOMThreadsShutdown in ThreadEventTarget::Dispatch, r=xpcom-reviewers,kmag,jstutte
Flags: needinfo?(nika)
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 102 Branch

Comment on attachment 9273674 [details]
Bug 1764119 - Part 2: Don't check gXPCOMThreadsShutdown in ThreadEventTarget::Dispatch, r=#xpcom-reviewers

Beta/Release Uplift Approval Request

  • User impact if declined: Shutdown crashes
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Medium
  • Why is the change risky/not risky? (and alternatives if risky): Changes to shutdown are always somewhat risky due to the weird interactions between different states which only come up in the real world and not in testing, but this patch has been on Nightly for a bit now.
  • String changes made/needed: None
  • Is Android affected?: Yes
Attachment #9273674 - Flags: approval-mozilla-beta?
Attachment #9273673 - Flags: approval-mozilla-beta?

Uplift request as requested by bug 1765393 comment 11

Comment on attachment 9273673 [details]
Bug 1764119 - Part 1: Do final KillClearOnShutdown after XPCOM threads shutdown, r=#xpcom-reviewers

We're still pretty early in the Beta cycle and this addresses a topcrash. Agreed that it's worth taking. Approved for 101.0b4.

Attachment #9273673 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9273674 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: