Skip to content

exit-watchdog: End a plugin's blocked DLL detach on Windows #4589

Closed

Description

@vpacher

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_watchdog that 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.

Out of scope

  • Ending the process ourselves after OBS's shutdown (TerminateProcess instead of returning from main()), 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

  1. 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?
  2. 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

  1. added
    bug
    on Nov 10, 2026
  2. vpacher commented on Nov 12, 2026

    @vpacher
    MemberAuthor

    Decision needed: what form does the Windows watchdog helper take (open question 1)?

    • A. A separate small exe next to 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, like obs64.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.
    • B. obs64.exe started 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.

  3. added
    decision-needed
    on Nov 12, 2026
  4. moved this from Triage to Needs decision in obs-rust Multiviewon Nov 12, 2026
  5. vpacher commented on Nov 13, 2026

    @vpacher
    MemberAuthor

    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)

    • Signing costs nothing extra for option A. ci/windows_sign.py puts every PE in the release ZIPs into the Azure Artifact Signing catalog (SIGNABLE includes .exe). A new helper exe next to obs64.exe is signed with no change to the release workflow.
    • The package already ships helper exes. obs-ffmpeg-mux (plugins/obs-ffmpeg/ffmpeg-mux/CMakeLists.txt:7), inject-helper and get-graphics-offsets (plugins/win-capture/) are separate executables that OBS starts. Option A follows that pattern.
    • Option B needs the flag before host init. main() in frontend/obs-main.cpp.hpp calls InstallPlatformAppSignalHandlers() and obs_main_host_early_init() before it reads argv. A --exit-watchdog flag would have to be checked before both, so that the helper process does not run OBS host setup.
    • The antivirus delay has a fix that works for both options. Start the helper with OBS and let it wait idle until the frontend arms it. Then a first-start scan is over long before quit.

    Options

    • A. Separate small exe, started with OBS, idle until armed (recommended). It loads no plugins and no OBS host code, it is signed automatically, and it has precedent in the package. The cost is one more file in the package. Per AGENTS.md, that change needs a packaged-artifact test that shows the helper present and working.
    • B. obs64.exe --exit-watchdog. Nothing new to package. The cost is that the flag must run before obs_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 clears human-review-needed and resumes the work.

  6. added
    human-review-needed
    and removed
    decision-needed
    on Nov 13, 2026
  7. vpacher commented on Nov 14, 2026

    @vpacher
    MemberAuthor

    Decided: option A, a separate small helper exe.

    • OBS starts it at startup; it waits idle until the frontend arms it at quit, so an antivirus scan of a new file is over long before it is needed.
    • It loads no plugins and no OBS host code. The release signing already covers it (ci/windows_sign.py signs every PE in the ZIPs), like obs-ffmpeg-mux.
    • The PR extends the packaged-artifact test to show the helper is present and ends a blocked quit (AGENTS.md packaging rule).
    • Question 2 keeps the default: when the helper cannot start, the in-process thread works as today.
  8. removed
    human-review-needed
    on Nov 14, 2026
  9. moved this from Needs decision to Triage in obs-rust Multiviewon Nov 14, 2026
  10. vpacher commented on Nov 14, 2026

    @vpacher
    MemberAuthor

    /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:

    • RED: the Tier 1 test from the body. A child loads a test DLL whose static destructor waits on an event that is never set, and the test expects exit code 124 and one watchdog line in the log.
    • The helper loads no plugins and no OBS host code, ships next to obs64.exe, and is signed by the existing release signing.
    • The packaged-artifact test shows that the helper is present and that it ends a blocked quit (AGENTS.md packaging rule).
    • When the helper cannot start, the in-process thread works as today.
      PR 2 (naming the DLL from the stack) stays a follow-up.
  11. added
    ready
    P2
    on Nov 14, 2026
  12. 1 remaining item

  13. vpacher commented on Nov 14, 2026

    @vpacher
    MemberAuthor

    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-watchdog binary only parses its arguments and calls it.

    • start() (new, Windows only; elsewhere it returns false) starts the helper. It passes:

      • the OBS process handle (SYNCHRONIZE | PROCESS_TERMINATE) and an arm event, through an explicit handle list (PROC_THREAD_ATTRIBUTE_HANDLE_LIST);
      • the timeout and the log path, as arguments.

      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 inside ExitProcess with 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 after create_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.
    • CMake installs obs-exit-watchdog.exe next to obs64.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.
    • A docs/features.md line.

    PR 3 (PR 2 of the body): name the DLL from the stack, as planned.

    Decisions:

    • Where the test hangs: the RED child hangs in a TLS callback of the test executable on DLL_PROCESS_DETACH, not in a separate test DLL. Windows runs the exe's TLS callbacks in ExitProcess, 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.
    • Helper name: obs-exit-watchdog.exe, the crate's name. It loads no plugins and no OBS host code.
    • Evidence: a PR that touches 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.

  14. moved this from Triage to In progress in obs-rust Multiviewon Nov 14, 2026
  15. moved this from In progress to Ready in obs-rust Multiviewon Nov 15, 2026
  16. vpacher commented on Nov 16, 2026

    @vpacher
    MemberAuthor

    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.rs uses the unsupported image 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(): SuspendThread and GetThreadContext on the armed thread, then RtlLookupFunctionEntry and RtlVirtualUnwind for 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 in exit() before ExitProcess).
    • RED: the existing host tests (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.

    • At 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.
    • On timeout, the helper suspends that thread and walks its stack from outside with dbghelp (StackWalk64 with SymFunctionTableAccess64/SymGetModuleBase64, as libobs/obs-win-crash-handler.c.h does), maps the frames through the table, and writes the named line. The OBS handle it gets adds PROCESS_VM_READ | PROCESS_QUERY_INFORMATION.
    • RED: the_helper_ends_a_hang_in_exit_process expects 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2bugreadysize:L

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions