Repository navigation
feat(exit-watchdog): a watchdog process ends a hang in ExitProcess on Windows (#4589) - #4858
Merged
Merged
Conversation
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
marked this pull request as ready for review
November 14, 2026 11:04
5 of 7 tasks
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
atexithandlers run in itsDLL_PROCESS_DETACH, insideExitProcess.ExitProcesshas 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 newobs-exit-watchdogbinary (src/bin/obs-exit-watchdog.rs, which only callsrun_helper()), next to the running executable:SYNCHRONIZE | PROCESS_TERMINATE) and creates a manual-reset arm event.PROC_THREAD_ATTRIBUTE_HANDLE_LIST, the same wayobs_util's Windows pipe does.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.OBS_EXIT_WATCHDOG_*). The helper has no window and no standard handles.run_helper(): the helper waits on both handles:TerminateProcess(124).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 inobs_util(not windows-sys: LNK2005 inobs.dll). Other hosts useplatform/no_helper.rsand never start a helper.The frontend start (
obs-main, right after the log file is created), the installation next toobs64.exe, the Windows packaged test and thedocs/features.mdline 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 withhelper_process_entryas its selector), arms it, and then blocks insideExitProcess. The block is in a TLS callback of the test executable onDLL_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_windowsruns off Windows.RED 24e7efa: stubs (
start_with()returns false, soarm()falls back to the thread). On Windows 11 (VM, MSVC), the hang case fails withthe 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:
exit_watchdogcases pass, with 0 failures over 20 runs of thehelpermodule.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-gpubinary, and no new test executable (the helper binary hastest = false). The longest is the hang case at about 1.2 s (1 s timeout plus the child). The wholehelpermodule 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, andrustfmt --checkpassed.ci/test_binary_cap.pyandci/test_naming.pypassed. There is no attestation, so PR CI runs the lanes. A change insrc/platform/windows*selects the Windows Rust lanes.🤖 Generated with Claude Code