Skip to content

frontend: End the process when exit() blocks after shutdown - #4309

Merged
vpacher merged 2 commits into
masterfrom
fix/4065-exit-watchdog
Nov 9, 2026
Merged

vpacher merged 2 commits into
masterfrom
fix/4065-exit-watchdog

Conversation

@vpacher

@vpacher vpacher commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Fixes #4065 (the watchdog; naming the blocking plugin is the follow-up proposed in the issue).

Problem

OBS can finish its shutdown and still not quit: a static destructor or atexit handler of a plugin blocks in exit() after main() has returned (#3739). The process then stays without a window and blocks the next start.

Change

  • New crate rust/obs-exit-watchdog, in the frontend's staticlib rust/obs-frontend, C ABI in frontend/utility/obs-exit-watchdog.h.
  • frontend/obs-main.cpp.hpp: after the Number of memory leaks line, obs_exit_watchdog_arm() with the current log file. Only when the frontend's Rust is built (OBS_FRONTEND_RUST), as the other frontend Rust features.
  • Arming prepares everything: it opens the log file in append mode, formats the line and starts one thread that sleeps for the timeout. When the process still runs then, the thread writes the line to the log file and stderr and ends the process with _exit(124) (Linux, macOS) or TerminateProcess (Windows). It does not call exit(), which would run the same destructors again, or abort(), which looks like a crash.
  • Line: exit-watchdog: exit did not finish in 10 s: a static destructor or atexit handler is blocking; ending the process. Timeout TIMEOUT = 10 s, exit code EXIT_CODE = 124, both named constants.
  • On a normal exit the sleeping thread ends with the process; nothing waits for it.
  • Windows: built and armed the same way, but ExitProcess ends the other threads before the DLLs' destructors run, so a plugin DLL that blocks there is probably not caught. To test on Windows first, as a follow-up.
  • docs/features.md: a Stability line.

Tests

  • RED 32fbe42: Tier 1 in obs-tests-gpu (the frontend's Rust category, no new binary) against todo!() stubs: 4 failed (not yet implemented: #4065; the blocked child ended with 101, not 124).
    • a_blocked_process_ends_with_one_line: a child (this test binary, exact selector) arms 200 ms with a log file, then blocks. It must end with 124 within 5 s, with one line on stderr and the line appended to the log file.
    • a_blocked_process_without_its_log_file_still_ends: the same with a log path in a missing directory: 124, one line on stderr.
    • a_normal_exit_is_not_delayed_and_writes_nothing: arms 4 s and returns: exit 0 in under 3 s, no line; a second arm returns false.
    • the_line_names_the_watchdog_and_the_timeout.
  • GREEN 9a2b8c8: the 4 pass, 0.22 s together on macOS and 0.20 s on Linux. ./lint passes on a Linux host; soldr cargo test -p obs-gpu-status --test obs-tests-gpu --locked --no-run --target x86_64-pc-windows-gnu links.
  • Tier 2/3: not applicable (new code, no C behavior changes).
  • Real app (macOS 27, arm64, RelWithDebInfo build of this branch), started from a shell, quit with an AppleEvent after 15 s:
    • Normal quit: exit code 0, 1.2 s from the quit request to the end of the process, no watchdog line. The watchdog only times the part after the leak line, where nothing runs but exit() (static destructors and atexit handlers), so its share of the 1.2 s is smaller; 10 s is more than 8 times the whole quit. Load on the machine changes little in that phase, because OBS's own teardown is already done.
    • With a test plugin in the user plugin folder whose function-local static (made in obs_module_load) joins a thread that never ends in its destructor (the Quitting the GUI does not end the process on Linux #3739 pattern): exit code 124, 11.05 s after the quit request. Log file:
      13:19:35.154: [exit-blocker] loaded: exit() will block in a static destructor
      13:19:49.920: Number of memory leaks: 0
      exit-watchdog: exit did not finish in 10 s: a static destructor or atexit handler is blocking; ending the process
      
      The same line on stderr; no OBS process left.
    • Not run in the Linux or Windows app: Linux takes the same _exit path as macOS and its Tier 1 cases pass; Windows is the follow-up above.
  • Test cost: longest case about 0.2 s (one child process each, three children); each child starts one thread (the watchdog's); no proptests.

🤖 Generated with Claude Code

vpacher and others added 2 commits November 9, 2026 13:23
OBS can finish its shutdown and still not quit when a plugin's static
destructor blocks in exit() (#3739). The new crate rust/obs-exit-watchdog
arms a thread that ends such a process; this commit has todo!() stubs and
its Tier 1 tests in obs-tests-gpu (the frontend's Rust category). The
cases that arm the watchdog re-run the test binary with an exact selector:
a blocked child must end with exit code 124 and one line in its log file
and on stderr, also without a log file; a normal exit must not wait and
writes nothing.

Refs #4065

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A plugin's static destructor or atexit handler can block exit() after
main() has returned, and OBS then stays without a window (#3739). After
the "Number of memory leaks" line, the frontend arms rust/obs-exit-watchdog
with the current log file. Arming opens the log file in append mode,
prepares the line and starts one sleeping thread. When the process still
runs after 10 s, the thread writes the line to the log file and stderr
and ends the process with _exit(124) (TerminateProcess on Windows): not
exit(), which runs the same destructors again, and not abort(), which
looks like a crash. Only when the frontend's Rust is built
(OBS_FRONTEND_RUST).

Fixes #4065

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher requested a review from zackees as a code owner November 9, 2026 12:35
@vpacher vpacher changed the title frontend: End the process when exit() blocks after shutdown (GREEN) frontend: End the process when exit() blocks after shutdown Nov 9, 2026
@vpacher
vpacher enabled auto-merge November 9, 2026 12:39
@vpacher
vpacher added this pull request to the merge queue Nov 9, 2026
@github-actions github-actions Bot added the claim-conflict A PR closing reference conflicts with the issue claim label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Claim conflict: keep this PR out of the merge queue until resolved.

@github-actions github-actions Bot removed the claim-conflict A PR closing reference conflicts with the issue claim label Nov 9, 2026
Merged via the queue into master with commit b0fd50e Nov 9, 2026
43 of 44 checks passed
@vpacher
vpacher deleted the fix/4065-exit-watchdog branch November 9, 2026 18:21
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Nov 10, 2026
…t#4584)

The quit-hang concept stopped at "Number of memory leaks". Since obs-rust#4309
the exit watchdog adds a last line, and since obs-rust#4560 that line names the
library and the plugin that loaded it. Add it as line 7, say how to read
the name and where it can mislead, and that gdb must attach within the
watchdog's 10 s.

Refs obs-rust#4525


Ci-Attestation: {"at":1794333181,"gate":"rust/all/fmt","host":"darwin-arm64","key":"","lane":"lint","parents":["edd24c57e13fc326fd79620d269ee3530dd548fe"],"secs":90,"stamp":"430982cd8ee5f2d77a15469a0b233205","tree":"ccfd658271982e6b830e48f1a9ecbbc301a7088a","v":1,"via":"run"}

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: OBS hangs after shutdown when a plugin's static destructor blocks (exit watchdog)

1 participant