Skip to content

feat(exit-watchdog): the helper names the DLL a hang in ExitProcess waits in (#4589) - #4891

Merged
vpacher merged 2 commits into
masterfrom
fix/4589-helper-names-dll
Nov 16, 2026
Merged

vpacher merged 2 commits into
masterfrom
fix/4589-helper-names-dll

Conversation

@vpacher

@vpacher vpacher commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Fixes #4589

Part 4, the last part of the plan in the claim: the helper process names the DLL that a hang inside ExitProcess waits in. Parts 1–3 are #4858, #4859 and #4890.

Problem

When a plugin DLL blocks in its DLL_PROCESS_DETACH (a static destructor, inside ExitProcess), the helper ended OBS, but its line named no library. It had neither the #4549 table nor the thread to walk. Example: Advanced Scene Switcher's sub-plugins in #3739.

Change

rust/obs-exit-watchdog:

  • Handover (helper.rs, portable):
    • encode_arm/decode_arm write and read the armed thread's id and the table. The format is a magic, the thread id, then each entry's range, owner tag and names.
    • A cut, empty or damaged section reads as nothing, and bytes after the end are ignored.
    • HelperArgs reads the optional section handle from OBS_EXIT_WATCHDOG_TABLE.
  • OBS side (platform/windows_helper.rs):
    • At start, OBS also creates an unnamed 1 MiB section and hands it over in the same explicit handle list. After CreateProcessW the section is made non-inheritable, as the event already is.
    • The OBS process handle the helper gets adds PROCESS_VM_READ | PROCESS_QUERY_INFORMATION.
    • arm() writes the table and the calling thread's id into the section, then sets the event.
    • If the section is missing, or the table does not fit, the helper works as before and its line names no library.
  • Helper side (helper.rs, platform/windows_stack.rs): on timeout, while OBS still runs, the helper:
    1. reads the section;
    2. opens and suspends that thread and reads its registers;
    3. walks its stack with dbghelp's StackWalk64 over OBS's memory (dbghelp is loaded at run time, as libobs/obs-win-crash-handler.c.h does);
    4. maps the frames through the table, writes the named line, and ends OBS.
  • arm64 Windows: no remote walk yet (a stub), so the line names no library there. This is the same limit as part 3.

docs/features.md: the "names the plugin" entry now covers a DLL that blocks while Windows unloads it.

Tests

All runs were on a Windows 11 VM (x64, MSVC), with soldr cargo test -p obs-gpu-status --test obs-tests-gpu exit_watchdog, on the commits after the rebase onto 01c5c1ec4 (#4890).

  • RED 76d8f066f: 27 passed; 4 failed.
    • args_read_every_value fails: the section handle is not read yet.
    • the_armed_thread_and_the_table_read_back and a_cut_or_damaged_section_reads_as_nothing fail on the todo!() stubs. These two portable tests run on every host.
    • windows::the_helpers_line_names_the_dll fails. A child starts the helper and arms it with a table that marks the test executable as loaded by blocker.dll. It then calls exit on that thread and blocks in its TLS callback inside ExitProcess, which is the state of a plugin DLL's detach. The test expects the helper's line to name the executable and blocker.dll.
  • GREEN a14c892e6: 31 passed; 0 failed. The helper's line from that child:
    exit-watchdog: exit did not finish in 1 s: a static destructor or atexit handler is blocking in obs_tests_gpu-6e48fcfe12c4c251.exe (loaded by blocker.dll); ending the process
    
  • Repeats: 20 runs of the exit_watchdog tests, 0 failures, longest 1.56 s.
  • Lint: clippy -D warnings --all-targets for obs-exit-watchdog and obs-gpu-status is clean on x86_64-pc-windows-msvc, aarch64-pc-windows-msvc and the macOS host; rustfmt is clean. arm64 Windows is compile-checked only.

Tiers: Tier 1 only. This is new Rust host code with no C original, so Tiers 2–4 do not apply.

Test cost: the new portable tests take microseconds. the_helpers_line_names_the_dll runs one child and one helper process for about 1 s (the timeout), as the existing helper tests do. The whole exit_watchdog group takes about 1.6 s.

Not checked: a full OBS build with a real plugin that blocks in its detach. test/packaged-startup.py (part 2) checks that the helper ends a blocked quit; it does not check the DLL name.

🤖 Generated with Claude Code

vpacher and others added 2 commits November 16, 2026 13:14
The helper ends a hang inside ExitProcess, but its line names no
library: it has neither the #4549 table nor the armed thread. Part 4
hands both over at arm time through a section the helper gets at start.

- args_read_every_value / args_without_a_good_table_have_none: the
  helper reads the section handle from OBS_EXIT_WATCHDOG_TABLE; it is
  optional, a bad value means none.
- the_armed_thread_and_the_table_read_back,
  a_cut_or_damaged_section_reads_as_nothing: encode_arm/decode_arm
  (stubs) round-trip the thread id and every owner kind; a cut, empty or
  damaged section reads as nothing.
- windows::the_helpers_line_names_the_dll: a child arms the helper with
  a table that marks the test executable as loaded by blocker.dll, then
  blocks in ExitProcess (its TLS callback); the helper's line must name
  the executable and blocker.dll (x64).

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

The helper ended a hang inside ExitProcess (a DLL's detach), but its
line named no library: it had neither the #4549 table nor the thread.

- At start, OBS also hands the helper an unnamed 1 MiB section, in the
  same explicit handle list (OBS_EXIT_WATCHDOG_TABLE); the process
  handle it gets adds PROCESS_VM_READ | PROCESS_QUERY_INFORMATION.
- arm() writes the table and the calling thread's id into the section
  (encode_arm: a magic, the thread, then each entry's range, owner and
  names), then sets the event. Without a section the helper works as
  before.
- On timeout, while OBS still runs, the helper reads the section
  (decode_arm), opens and suspends that thread, reads its registers and
  walks its stack with dbghelp's StackWalk64 (loaded at run time, as
  libobs/obs-win-crash-handler.c.h does), then writes the line naming the
  first frame's library outside OBS, and ends OBS.

x64 only for the walk; arm64 Windows still writes the line without a
library.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher requested a review from zackees as a code owner November 16, 2026 12:15
@vpacher
vpacher enabled auto-merge November 16, 2026 12:17
@vpacher
vpacher added this pull request to the merge queue Nov 16, 2026
Merged via the queue into master with commit 8e1b3ed Nov 16, 2026
41 checks passed
@vpacher
vpacher deleted the fix/4589-helper-names-dll branch November 16, 2026 12:53
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.

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

1 participant