Skip to content

feat(exit-watchdog): a watchdog process ends a hang in ExitProcess on Windows (#4589) - #4858

Merged
vpacher merged 2 commits into
masterfrom
feat/4589-exit-watchdog-helper
Nov 14, 2026
Merged

vpacher merged 2 commits into
masterfrom
feat/4589-exit-watchdog-helper

Conversation

@vpacher

@vpacher vpacher commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Refs #4589 (PR 1 of 3: the helper and its test. Nothing in OBS starts it yet.)

Problem

On Windows, a plugin DLL's static destructors and atexit handlers run in its DLL_PROCESS_DETACH, inside ExitProcess. ExitProcess has ended every other thread before that, the watchdog thread of #4309 too. A destructor that waits for a signal that never comes hangs OBS forever, and the watchdog cannot see it. Only another process can end it.

Change

rust/obs-exit-watchdog:

  • helper::start() / start_with() start the new obs-exit-watchdog binary (src/bin/obs-exit-watchdog.rs, which only calls run_helper()), next to the running executable:
    • OBS duplicates its own process handle (SYNCHRONIZE | PROCESS_TERMINATE) and creates a manual-reset arm event.
    • It passes only those two through PROC_THREAD_ATTRIBUTE_HANDLE_LIST, the same way obs_util's Windows pipe does.
    • Right after CreateProcessW, it closes the process handle and clears the event's inherit flag, so the processes that OBS starts later (obs-ffmpeg-mux, CEF, QProcess) do not inherit them.
    • The handle values, the timeout and the log path go through the helper's environment (OBS_EXIT_WATCHDOG_*). The helper has no window and no standard handles.
  • run_helper(): the helper waits on both handles:
    • When OBS ends, the helper ends (exit code 0).
    • Once armed, it waits on OBS for the timeout. Then it appends the watchdog line to the log and calls TerminateProcess(124).
    • It detects the end of OBS through the process handle only, never through a handle that closed.
    • An incomplete environment gives exit code 2.
  • arm(): when a helper runs, arm() sets the event and starts no thread, so the line is written once. Without a helper, it starts the thread as before (open question 2 of exit-watchdog: End a plugin's blocked DLL detach on Windows #4589).
  • platform/windows_helper.rs: the Win32 calls, declared against kernel32 as in obs_util (not windows-sys: LNK2005 in obs.dll). Other hosts use platform/no_helper.rs and never start a helper.

The frontend start (obs-main, right after the log file is created), the installation next to obs64.exe, the Windows packaged test and the docs/features.md line are PR 2. Naming the DLL from the stack is PR 3.

Tests

obs-tests-gpu, exit_watchdog::helper:

  • windows::the_helper_ends_a_hang_in_exit_process: a child starts the helper (the test executable itself, run with helper_process_entry as its selector), arms it, and then blocks inside ExitProcess. The block is in a TLS callback of the test executable on DLL_PROCESS_DETACH, which waits on an event that nobody sets. Windows runs the executable's TLS callbacks there after it has ended the other threads, which is the state a plugin DLL's destructor runs in. Before writing it, I checked on Windows 11 with a small exe that such a callback hangs even with an armed watchdog thread. The test expects exit code 124 and the line appended to the log.
  • windows::the_helper_lets_a_normal_exit_go: with an armed helper, a normal exit ends with 0, and no line follows after the timeout.
  • windows::without_a_helper_the_thread_still_ends_a_hang_in_exit: no helper file means the thread works as today.
  • args_*: the helper's environment parsing (both handles and the timeout needed, 0 handles and bad numbers rejected, the log optional), on every host. start_does_nothing_off_windows runs off Windows.

RED 24e7efa: stubs (start_with() returns false, so arm() falls back to the thread). On Windows 11 (VM, MSVC), the hang case fails with the child still ran after 5s: that is the bug. The args and normal-exit cases fail at the stubs.

GREEN (this commit): results by host:

  • Windows 11: all 25 exit_watchdog cases pass, with 0 failures over 20 runs of the helper module.
  • Linux: 23 pass (the Windows module is not built there).
  • macOS: not run, because soldr does not start on my Mac today. The code there is the same as on Linux, with no helper.

Also on Windows: the helper binary is 167 KB in a debug build, and started with no environment it exits with code 2.

Tiers: Tier 1. No Tier 2, 3 or 4: no C code or protocol changes.

Test cost: 8 new tests in the existing obs-tests-gpu binary, and no new test executable (the helper binary has test = false). The longest is the hang case at about 1.2 s (1 s timeout plus the child). The whole helper module takes at most 1.55 s over 20 runs on Windows. Each Windows case starts two short child processes; there are no threads of the tests' own.

Local checks: clippy --all-targets -D warnings (obs-exit-watchdog, obs-gpu-status) passed on Windows and Linux, and rustfmt --check passed. ci/test_binary_cap.py and ci/test_naming.py passed. There is no attestation, so PR CI runs the lanes. A change in src/platform/windows* selects the Windows Rust lanes.

🤖 Generated with Claude Code

vpacher and others added 2 commits November 14, 2026 10:36
A plugin DLL's static destructor runs in DLL_PROCESS_DETACH inside
ExitProcess, which has ended the watchdog thread first; a destructor that
waits for a signal hangs OBS forever. The helper module and the
obs-exit-watchdog binary are stubs: start_with() returns false, so arm()
falls back to the thread as today.

Tier 1 (obs-tests-gpu, exit_watchdog::helper): a child arms the helper and
then blocks in a TLS callback of the test executable on
DLL_PROCESS_DETACH, the state a plugin DLL's destructor runs in. It
expects exit code 124 and one line in the log; today it hangs. Also: a
normal exit with an armed helper, the thread fallback without a helper,
and the helper's environment parsing on every host.

Refs #4589

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… Windows (#4589)

A plugin DLL's static destructor runs in DLL_PROCESS_DETACH inside
ExitProcess, after Windows has ended every other thread, the watchdog
thread too. A destructor that waits for a signal then hangs OBS forever;
only another process can end it.

helper::start() starts the obs-exit-watchdog binary next to the running
executable. It duplicates its own process handle (SYNCHRONIZE |
PROCESS_TERMINATE) and creates a manual-reset arm event, passes only
those two through PROC_THREAD_ATTRIBUTE_HANDLE_LIST, and closes the
process handle and clears the event's inherit flag right after
CreateProcessW, so later children do not inherit them. The handle values,
the timeout and the log path go through the helper's environment. The
helper waits on both handles: when OBS ends it ends; once armed it waits
for the timeout, appends the watchdog line to the log and calls
TerminateProcess(124). It sees the end of OBS through the process handle
only.

arm() sets the event instead of starting the thread when a helper runs,
so the line is written once; without a helper it starts the thread as
before. Other hosts never start a helper. Nothing starts it in OBS yet:
the frontend and the packaging are the next PR of #4589.

Refs #4589

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher marked this pull request as ready for review November 14, 2026 11:04
@vpacher
vpacher requested a review from zackees as a code owner November 14, 2026 11:04
@vpacher
vpacher added this pull request to the merge queue Nov 14, 2026
@vpacher vpacher mentioned this pull request Nov 14, 2026
5 of 7 tasks
Merged via the queue into master with commit 848c20b Nov 14, 2026
42 checks passed
@vpacher
vpacher deleted the feat/4589-exit-watchdog-helper branch November 14, 2026 11:23
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.

1 participant