servo/components/background_hang_monitor
Gregory Terzian 815ed10b5f
background_hang_monitor: ensure workers run until monitored components do (#38322)
Shut-down of the background hang monitor(bhm) is currently  problematic:

- it does not always run until the monitored script-thread does(see
"BackgroundHangMonitor has gone away" mentioned in
https://github.com/servo/servo/issues/34158).
- it shuts-down before the constellation(good, so actually
https://github.com/servo/servo/issues/24850 was "fixed" but in a way
that introduced a new problem), but using a mechanism that allows it to
shutdown before script(the problem above).
- there are various mechanism(see the doc comments removed by this PR)
in place which are meant to ensure a clean shutdown despite the above
problems; those are complicated, and become unnecessary once those
problems are fixed.

All of the above is fixed by the changes in this PR, which ensure the
bhm does not shut-down before script, and also maintains the invariant
that it must shut-down before the constellation(in single-process mode)
or before the main thread(in multi-process mode), but using a mechanism
which allows it to keep running until script shuts-down.

An unnecessary option around the exit signal is also removed.

As a positive side-effect, it also ensures that any script-thread is
shut-down before the constellation(because for the bhm worker to exit,
the monitored script must have exited first), so this should also fix a
host of other problems noted in
https://github.com/servo/servo/issues/30849, but each should be
confirmed independently(and various other improvements seem possible in
their specific contexts, such as joining on script threads, and removing
the `ScriptThreadMessage::ExitScriptThread`).

Fixes: https://github.com/servo/servo/issues/24850 and part of
https://github.com/servo/servo/issues/34158

Testing: Unit tests in `component/background_hang_monitor/tests`. Also
manually tested loading "about-blank" in single- and multi-process mode.

---------

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
2025-07-30 13:03:28 +00:00
..
tests background_hang_monitor: ensure workers run until monitored components do (#38322) 2025-07-30 13:03:28 +00:00
background_hang_monitor.rs background_hang_monitor: ensure workers run until monitored components do (#38322) 2025-07-30 13:03:28 +00:00
Cargo.toml bhm: Add backtrace demangling (#37819) 2025-07-02 13:39:36 +00:00
lib.rs Enable LinuxSampler to be used on Android (#37784) 2025-06-30 17:17:50 +00:00
sampler.rs bhm: Add backtrace demangling (#37819) 2025-07-02 13:39:36 +00:00
sampler_linux.rs Replace unwind-sys with backtrace crate on Linux (#37728) 2025-06-27 12:20:10 +00:00
sampler_mac.rs chore: Move unsafe operations in unsafe functions to unsafe blocks (#36017) 2025-03-18 06:19:35 +00:00
sampler_windows.rs deps: Switch from winapi to windows_sys in Servo code (#32516) 2024-06-17 08:27:50 +00:00