Skip to content

bug: frontend: the exit watchdog does not name the plugin that blocks exit #4525

Closed

Description

@vpacher

Follow-up to #4065 (closed by #4309, the watchdog itself). This issue is steps 2 and 3 of the order in my #4065 comment: name the module.

Problem

Since #4309, OBS ends the process when exit() does not finish in 10 s, and writes one line:

exit-watchdog: exit did not finish in 10 s: a static destructor or atexit handler is blocking; ending the process

The line does not say which plugin blocks. In #3739 that was the hard part: the cause was a sub-plugin of Advanced Scene Switcher (its MIDI support, with libremidi). We found it only with a debugger on a test machine with the reporter's plugin set. The OBS log cannot show it today:

  • Loaded Modules: names only the modules that libobs loads. advss loads its sub-plugins with its own dlopen, so the list names only advss.
  • obs_shutdown() frees obs->first_module before the watchdog arms, so the watchdog cannot read the module list.

Location

  • libobs/obs-module.c.h: obs_open_module(), obs_init_module() (record the libraries that each module brings in).
  • rust/obs-exit-watchdog (find the library where the main thread waits, and write it in the line).
  • frontend/obs-main.cpp.hpp (no change expected; the watchdog arms there).

Class

Diagnostics. No change to the module API or ABI. Existing plugin binaries need no rebuild.

How it is reached

A plugin, or a library that a plugin loads, blocks in a static destructor or an atexit handler. The user quits OBS, and the watchdog fires after 10 s.

Proposed fix and failing test

Two PRs.

PR 1: record which module brought in which libraries.

  • Around os_dlopen(), obs_init_module() and post_load of each module, compare the loaded images of the process before and after. The new images belong to that module (for example advanced-scene-switcher: midi.so, libremidi.so). The table stays until exit and does not depend on obs->first_module.
  • Linux: dl_iterate_phdr. macOS: _dyld_image_count / _dyld_get_image_name (or _dyld_register_func_for_add_image).
  • The diff is a pure function (images before, images after, owner), with Tier 1 tests against todo!() stubs first (RED).
  • Limits: a library that a plugin thread loads during the load of another module gets the wrong owner. A library loaded later at run time shows as "loaded after startup", with no owner. OBS does not intercept dlopen.

PR 2: name the library in the watchdog line.

  • When the watchdog fires, take the main thread's stack, map each return address to an image in the table, and write the first image that is not a system library, with its owner:

    exit-watchdog: exit did not finish in 10 s: a static destructor or atexit handler is blocking in midi.so (loaded by advanced-scene-switcher); ending the process
    
  • Linux: send a real-time signal to the main thread. The handler only calls backtrace() into a static buffer; the watchdog thread does the lookup and the write. The handler is installed only when the watchdog fires.

  • macOS: no signal. thread_suspend() and thread_get_state() on the main thread, then a frame-pointer walk.

  • RED: extend the frontend: End the process when exit() blocks after shutdown #4309 re-exec test. The child loads a test library with a static destructor that joins a thread that never ends; the watchdog line must name that library and its owner. A manual check with the same plugin in the real app goes in the PR.

Out of scope

Open questions

  1. Should the startup log list the extra libraries of each module? If yes, at info level with system libraries left out, or only at debug level?
  2. File names only, as Loaded Modules: does? Full paths can contain the user name.

Activity

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

    @vpacher
    MemberAuthor

    /ready

    Claiming: #4525 (both PRs of the issue body, one at a time).

    Plan:

    1. PR 1: the table of which module brought in which libraries (libobs, around obs_open_module() / obs_init_module()), Linux and macOS. RED: Tier 1 tests for the before/after diff against todo!() stubs.
    2. PR 2: the name in the exit watchdog line, from the main thread's stack and the table of PR 1. RED: the frontend: End the process when exit() blocks after shutdown #4309 re-exec test with a test library whose static destructor blocks.

    Decisions:

    • Question 1 (list the extra libraries at startup): not in this issue. The table stays in memory for the watchdog only. A debug-level startup listing can follow if someone asks for it.
    • Question 2 (paths): file names only, as Loaded Modules: does, so the log does not show the user name.

    First PR (RED) expected 2026-11-11.

  3. added
    ready
    on Nov 10, 2026
  4. vpacher commented on Nov 10, 2026

    @vpacher
    MemberAuthor

    Progress on PR 1, with a change of location: the table goes into the frontend's Rust next to the exit watchdog (rust/obs-exit-watchdog), not into libobs.

    • The reader is the watchdog in the frontend. A table in libobs would need a new libobs export, and hybrid libobs must export exactly the C reference's symbols.
    • No per-module hook is needed. The process's image list is in load order on Linux (dl_iterate_phdr) and macOS (dyld): a dlopen adds the library and the dependencies it pulls in at the end, and earlier entries keep their place (checked on both). So a module's extra libraries come right after it. Advanced Scene Switcher loads its sub-plugins in its obs_module_load, so in Quitting the GUI does not end the process on Linux #3739 midi.so and libremidi.so would follow advanced-scene-switcher.
    • The frontend takes the image list after the plugins load, after post-load, and when the watchdog arms. An image's owner is the last OBS module before it in the list (module paths from obs_enum_modules). Images before the first module belong to OBS itself, and images new after loading are "loaded in post-load" or "loaded after startup".
    • Windows: a stub for now (step 4 of the bug: OBS hangs after shutdown when a plugin's static destructor blocks (exit watchdog) #4065 order).

    PR 1: the attribution as a pure function plus the snapshots, with Tier 1 tests in obs-tests-gpu. No libobs change, and no log output yet (that's PR 2).

  5. vpacher commented on Nov 10, 2026

    @vpacher
    MemberAuthor

    Claiming: #4525 (continuing the claim above: PR 1 #4549 is merged, PR 2 is #4560).

  6. vpacher commented on Nov 10, 2026

    @vpacher
    MemberAuthor

    Fixed by #4549 (which module brought in which libraries) and #4560 (the watchdog line names the library and its module), on Linux and macOS.

    The line now reads, for example:

    exit-watchdog: exit did not finish in 10 s: a static destructor or atexit handler is blocking in libremidi.so.4 (loaded by advanced-scene-switcher.so); ending the process
    

    The owner is one of: the module itself (an OBS module), the module that loaded the library (loaded by <module>), loaded during the modules' post-load, or loaded after startup. When the stack has only OBS's own frames, or the host cannot capture it, the line stays as it was before.

    Changes from the plan in the issue:

    • PR 1 does not compare image lists around each os_dlopen(). The process's image list is in load order on both hosts, so the owner of a library is the last OBS module before it in that list. libobs needed no change: the frontend notes the modules and the image list after loading and after post-load (PluginManager.cpp.hpp), and the watchdog builds the table when it is armed.
    • On macOS, libobs names a plugin by its bundle (name.plugin) and dyld by the binary inside it. A module now also matches a directory of the image's path.

    Checked by hand in the macOS app with a test plugin that blocks in a static destructor: exit code 124 after 11 s, and the line names the plugin as an OBS module. A normal quit ends in 1 s with exit code 0.

    Open question 1 (list each module's extra libraries in the startup log): not done. The table is only built for the watchdog. I suggest we add it only if a report needs it.

    Left:

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

Metadata

Metadata

Assignees

Labels

bugready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions