Repository navigation
Description
Follow-up to #4065 and #4525. This issue is step 4 of the order in my #4065 comment: the exit watchdog on Windows.
Problem
On Linux and macOS, the exit watchdog (#4309) ends OBS when exit() does not finish in 10 s. Since #4560 its line also names the plugin. On Windows the same watchdog thread is armed, but it cannot cover plugins.
libobs never unloads a module's library, so a plugin DLL's static destructors and atexit handlers run in its DLL_PROCESS_DETACH, during ExitProcess. ExitProcess ends every other thread of the process before that. The watchdog thread is gone by then, so it can only catch a hang in the exe's own exit() phase.
I checked this on Windows 11 (MSVC, /MD) with a small exe that loads a test DLL like a module (LoadLibrary, then an exported start function, never FreeLibrary), arms a watchdog, and returns from main(). The DLL has a static object whose destructor blocks in one of several ways. Each case ran with an in-process watchdog thread and with a watchdog process (a child that waits on the parent's handle and terminates it), both after 5 s:
| The destructor | Watchdog thread | Watchdog process |
|---|---|---|
Exe static destructor blocks (in exit()) |
ends it, exit code 124 | ends it, exit code 124 |
| DLL: joins a thread that never ends | no hang: join returns at once, exit code 0 |
same |
DLL: locks a std::mutex or enters a CRITICAL_SECTION that another thread holds |
no hang: the process ends at once with exit code 0, the destructor never finishes | same |
| DLL: waits for an event another thread would set | hangs | ends it, exit code 124 |
DLL: waits on a std::condition_variable |
hangs | ends it, exit code 124 |
DLL: Sleep(INFINITE) |
hangs | ends it, exit code 124 |
So the #3739 case (a destructor that joins a thread that waits on a lock) does not hang on Windows: the joined thread is already terminated. A destructor that waits for a signal from a thread that no longer exists, or that blocks on its own, hangs forever. Only something outside the process can end it.
Location
rust/obs-exit-watchdog:src/platform/windows.rs,src/lib.rs(arm).frontend/obs-main.cpp.hpp: no change expected; the watchdog arms there.
Class
Diagnostics and robustness on Windows. No change to the module API or ABI.
How it is reached
A plugin DLL blocks in a static destructor or an atexit handler, for example while it waits for a worker thread's "done" signal. The user quits OBS. The window closes and the process stays.
Proposed fix and failing test
Two PRs, like #4525.
PR 1: a watchdog process on Windows.
- When the watchdog arms on Windows, it starts a helper process and passes it the OBS process handle (inherited), the timeout and the log path. The helper waits on the handle. On timeout it writes the watchdog line to the log and calls
TerminateProcess(124). When OBS ends in time, the helper ends too. - The in-process thread is not used on Windows: the helper covers the exe's
exit()phase as well. - RED: a Tier 1 test in
exit_watchdogthat runs a child which loads a test DLL whose static destructor waits on an event that is never set. It expects exit code 124 and one line in the log. Today the child hangs, so the test bounds it and fails.
PR 2: name the DLL.
- The helper suspends the main thread, reads its context and walks its stack from outside (
SuspendThread,GetThreadContext,StackWalk64overReadProcessMemory). It maps the frames to modules with the same owner rule as obs-exit-watchdog: Record which module brought in which libraries #4549, using the image list that OBS writes when the watchdog arms.
Out of scope
- Ending the process ourselves after OBS's shutdown (
TerminateProcessinstead of returning frommain()), so that no plugin detach code runs. That would also skip the work plugins do at exit, such as flushing files. It needs a discussion first. - The silent exit code 0 when a destructor waits on a lock that a terminated thread holds. Windows ends the process itself there; nothing hangs.
Open questions
- The helper: a separate small exe that ships next to OBS, or the OBS exe itself started with a flag? A separate exe starts faster and loads no plugins, but it is one more file to package and sign. In the test, the first start of a newly built exe took about 16 s, probably an antivirus scan. The watchdog arms at quit, so a helper started then can still be in that scan when OBS hangs. Should the helper instead start with OBS and wait idle until the frontend arms it?
- Should the watchdog also arm on Windows when the helper cannot start, with the thread as a fallback for the exe's
exit()phase only?
Activity
vpacher commentedon Nov 12, 2026
Decision needed: what form does the Windows watchdog helper take (open question 1)?
obs64.exe. It starts fast and loads no plugins. But it is one more file to package, and release builds must sign it (Azure Artifact Signing, likeobs64.exe). An unsigned new exe can also be held by an antivirus scan on its first start (about 16 s in my test), and the helper must be ready before OBS hangs.obs64.exestarted with a flag (for example--exit-watchdog). Nothing new to package or sign. But the helper is a second OBS process, and the flag must stop it before it loads plugins or opens a window.Either form can start at quit or start with OBS and wait until the frontend arms it. That choice follows from this one.
Open question 2 has a safe default: when the helper cannot start, keep the in-process thread as today. It still covers the exe's own
exit()phase.The work waits for this answer.
vpacher commentedon Nov 13, 2026
Coordinator: escalated to
human-review-needed. No rule settles open question 1, and the choice changes what ships in the Windows package. Findings and a recommendation follow.What I checked on master (3e5f397)
ci/windows_sign.pyputs every PE in the release ZIPs into the Azure Artifact Signing catalog (SIGNABLEincludes.exe). A new helper exe next toobs64.exeis signed with no change to the release workflow.obs-ffmpeg-mux(plugins/obs-ffmpeg/ffmpeg-mux/CMakeLists.txt:7),inject-helperandget-graphics-offsets(plugins/win-capture/) are separate executables that OBS starts. Option A follows that pattern.main()infrontend/obs-main.cpp.hppcallsInstallPlatformAppSignalHandlers()andobs_main_host_early_init()before it readsargv. A--exit-watchdogflag would have to be checked before both, so that the helper process does not run OBS host setup.Options
obs64.exe --exit-watchdog. Nothing new to package. The cost is that the flag must run beforeobs_main_host_early_init(), and a second OBS process stays alive for the whole session.Open question 2 keeps the default from the decision request: when the helper cannot start, the in-process thread stays as today.
To answer, post a comment whose first line starts with
Decided:. It clearshuman-review-neededand resumes the work.vpacher commentedon Nov 14, 2026
Decided: option A, a separate small helper exe.
ci/windows_sign.pysigns every PE in the ZIPs), likeobs-ffmpeg-mux.vpacher commentedon Nov 14, 2026
/ready
Coordinator triage after the decision of 2026-11-14 08:41 UTC (option A). This is PR 1 of the plan in the body: a separate helper exe, started with OBS, idle until the frontend arms it at quit. Acceptance:
obs64.exe, and is signed by the existing release signing.PR 2 (naming the DLL from the stack) stays a follow-up.
1 remaining item
vpacher commentedon Nov 14, 2026
Claiming: #4589
Plan after the decision (option A). PR 1 of the body is split in two, so the helper and its test land before the packaging change.
PR 1: the helper and its test (
rust/obs-exit-watchdog).The helper logic is a library function. The crate's new
obs-exit-watchdogbinary only parses its arguments and calls it.start()(new, Windows only; elsewhere it returns false) starts the helper. It passes:SYNCHRONIZE | PROCESS_TERMINATE) and an arm event, through an explicit handle list (PROC_THREAD_ATTRIBUTE_HANDLE_LIST);OBS closes its inheritable copies right after
CreateProcess, so the children that OBS starts later (obs-ffmpeg-mux, CEF,QProcess) do not inherit them.The helper waits on both handles. If OBS ends first, the helper ends. If the event is set, the helper waits on the process for the timeout, then 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 closed handle.arm(): when the helper runs, it sets the event and starts no thread, so the line is written once. When the helper did not start, the thread works as today (question 2).RED: a Tier 1 case in
exit_watchdog. Its child starts the test binary itself as the helper, then blocks insideExitProcesswith a wait on an event that is never set. Today it hangs, and the test bounds it; with the fix it expects exit code 124 and one line in the log.PR 2: OBS starts the helper (frontend, packaging).
obs-main:start()right aftercreate_log_file(), when the log path is known. The helper is therefore running long before quit, and a first-start antivirus scan is over by then.obs-exit-watchdog.exenext toobs64.exe. The release signing covers it (ci/windows_sign.py).test/packaged-startup.py(the Windows release lane) checks that the helper is present, and that it ends a quit that a test plugin blocks.docs/features.mdline.PR 3 (PR 2 of the body): name the DLL from the stack, as planned.
Decisions:
DLL_PROCESS_DETACH, not in a separate test DLL. Windows runs the exe's TLS callbacks inExitProcess, after it has ended the other threads, which is the same state as a plugin DLL's detach. It needs no extra build target. I check on Windows first that this case hangs with today's thread watchdog. If it does not, I build a test DLL as the body says.obs-exit-watchdog.exe, the crate's name. It loads no plugins and no OBS host code.src/platform/windows*starts the Windows Rust lanes (ci/ci_scope.py). I also run RED and GREEN on a Windows 11 VM.PR 1 opens as a draft once its RED case has run on Windows.
test(packaging): RED for the exit watchdog helper in the Windows pack…
feat(frontend): start the exit watchdog's helper process on Windows (#…
vpacher commentedon Nov 16, 2026
Claiming: #4589 (continuing: part 3, name the DLL; parts 1 and 2 merged in #4858 and #4859)
On Windows the watchdog line names no library yet:
platform/mod.rsuses theunsupportedimage list and stack capture there. Plan, two PRs:PR 3: the image list and the stack capture on Windows (in-process).
images(): the loaded modules in load order through Toolhelp (CreateToolhelp32Snapshot(TH32CS_SNAPMODULE),Module32FirstW/Module32NextW), so the obs-exit-watchdog: Record which module brought in which libraries #4549 owner rule works unchanged. I check on Windows that the order is the load order: the executable first, a library loaded later comes last.capture_stack():SuspendThreadandGetThreadContexton the armed thread, thenRtlLookupFunctionEntryandRtlVirtualUnwindfor each frame (x64 and arm64), into the fixed buffer, with no allocation and no dbghelp. This names the DLL when the in-process thread fires (no helper, or a hang inexit()beforeExitProcess).the_host_lists_its_images_in_load_order,another_threads_stack_is_captured,a_blocked_process_names_the_library) take their "not supported" branch on Windows today; a Windows test that requires both capabilities fails until the GREEN commit.PR 4: the helper names the DLL.
arm(), OBS writes the table (obs-exit-watchdog: Record which module brought in which libraries #4549 owners) and the armed thread id into a section that the helper got at start with the other handles.StackWalk64withSymFunctionTableAccess64/SymGetModuleBase64, aslibobs/obs-win-crash-handler.c.hdoes), maps the frames through the table, and writes the named line. The OBS handle it gets addsPROCESS_VM_READ | PROCESS_QUERY_INFORMATION.the_helper_ends_a_hang_in_exit_processexpects the line to name the test executable (its TLS callback is where the child blocks).Evidence: RED and GREEN on a Windows 11 VM (x64); the PRs touch
src/platform/windows*, so the Windows Rust lanes run. arm64 is compile-checked only (clippy), which I will say in the PR.First PR expected today or tomorrow.
feat(exit-watchdog): a watchdog process ends a hang in ExitProcess on…
feat(frontend): start the exit watchdog's helper process on Windows (o…
feat(exit-watchdog): the image list and stack capture on Windows (obs…
feat(exit-watchdog): the helper names the DLL a hang in ExitProcess w…