Repository navigation
Description
Promoted from discussion #4051 (@vpacher).
Problem
OBS can finish its own shutdown and still not quit. In #3739 the log ends with Number of memory leaks, and the process stays alive with no window. The hang was in a static destructor of a third-party plugin: at exit(), a library in the plugin joined a thread that never stopped. OBS had no code left on the stack.
OBS cannot stop one plugin: a plugin is a shared library inside the OBS process, not a process of its own. libobs also never unloads modules (os_dlclose is commented out in free_module), so every plugin's destructors run at exit(), after main() returns.
For the user this is a process that never ends — it can block the next start, a restart, or a system shutdown. For us it is a long hunt: #3739 needed a test machine, the reporter's plugin set and a debugger to identify the plugin.
Proposed fix (from the discussion)
An exit watchdog for the last step of the process:
- In
frontend/obs-main.cpp.hpp, afterobs_main_host_shutdown()and theNumber of memory leaksline, start a detached thread with a timeout of some seconds. - If the process still runs when the timeout expires, the thread writes one line naming the situation ("exit did not finish in N s: a static destructor or atexit handler is blocking") and terminates the process rather than hanging forever.
Why high priority
- It produces a user-visible hang that survives shutdown, blocking restarts and system power-off, and it is indistinguishable from a crash for support purposes.
- Diagnosis is expensive: the failing plugin is invisible in the OBS log, and finding it required a debugger and a reproduction from the reporter.
- The fix is small, local (one file), and converts an open-ended hang into a bounded, diagnosable exit.
Acceptance criteria
- After
obs_main_host_shutdown()and the leak report, a watchdog with a bounded timeout is armed. - If shutdown completes normally, the watchdog never fires and nothing is logged.
- If a static destructor/atexit handler blocks past the timeout, OBS writes exactly one diagnostic line naming the timeout, and the process exits non-zero instead of hanging.
- The timeout is configurable or at least a single named constant; a machine-readable log line is preferred over prose.
- A test (or a documented manual reproduction with a plugin that joins a never-terminating thread) proves the watchdog fires and the process ends.
- No behaviour change when shutdown is healthy: no extra threads left running, no measurable delay on a normal exit.
Notes
- The watchdog must not mask a genuine slow shutdown: the timeout needs to be comfortably longer than normal teardown on a loaded machine, and the log line must say it was the watchdog, not OBS, that ended the process.
- Consider whether to name the loaded modules in the diagnostic, so the next occurrence identifies the plugin without a debugger.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
vpacher commentedon Nov 8, 2026
A proposal for the "name the loaded modules" note, as follow-ups after the watchdog itself. All of it is in libobs and the frontend: no change to the module API or ABI, and existing plugin binaries need no rebuild.
Why the module list is not enough
libobs already logs
Loaded Modules:at startup, but in #3739 that list would not have named the cause:dlopen, so libobs never sees them. The list names only advss.obs_shutdown()freesobs->first_modulebefore the watchdog arms, so the watchdog cannot read the list at that point.Proposal
1. Record which module brought in which libraries. Around
os_dlopen(),obs_init_module()andpost_loadof each module, compare the process's loaded images before and after. The new images belong to that module (for exampleadvanced-scene-switcher: midi.so, libremidi.so). Keep the table until exit; it does not depend onobs->first_module.dl_iterate_phdr. macOS:_dyld_register_func_for_add_imageor_dyld_image_count. Windows:EnumProcessModulesorLdrRegisterDllNotification.dlopen; we do not propose that, because it changes what plugins call.2. Name the library where the main thread waits. When the watchdog fires, take the main thread's stack, map each return address to an image of the table, and write the first image that is not a system library, with its owner from 1, in the same line:
backtrace()into a static buffer; the watchdog thread does the lookup and the write. The handler is installed only when the watchdog fires, so it cannot conflict with a plugin's signal use during normal operation.thread_suspend()andthread_get_state()on the main thread, then a frame-pointer walk.ExitProcessends the other threads beforeDLL_PROCESS_DETACH, so the watchdog thread may not be alive when DLL destructors run, and the Quitting the GUI does not end the process on Linux #3739 pattern may not hang there in the same way.Considered and not proposed
An
atexitbreadcrumb after each module load (the last one that ran brackets the blocking module). It misses statics made at run time, which was the #3739 case, and destructor functions that do not go through theatexitlist.Suggested order
Questions
Loaded Modules:does? Full paths can contain the user name.vpacher commentedon Nov 9, 2026
/ready
Claiming: the exit watchdog (step 1 of the order in my comment above; no module naming in this PR).
Plan, one PR:
rust/obs-exit-watchdog(laid out likeobs-camera-busy:src/ffi/,src/platform/), re-exported fromrust/obs-frontend, withtodo!()stubs. Tier 1 tests as a module inobs-tests-gpu(the frontend's Rust category), no new test binary. Each case re-runs the test binary with an exact selector:frontend/utility/, and the call infrontend/obs-main.cpp.hppafter theNumber of memory leaksline.docs/features.mdline.First PR (RED) expected today.
Decisions:
main()has returned, the log file object is closed and static destructors are running. So arming opens the current log file in append mode and formats the line; firing only writes it (to the log file and stderr) and ends the process with_exit()(Linux, macOS) orTerminateProcess()(Windows). Notexit(), which runs the same destructors again, and notabort(), which looks like a crash.exit-watchdog: exit did not finish in <N> s: a static destructor or atexit handler is blocking; ending the process, and a named exit code that is not 0.ExitProcessends the other threads before the DLLs' destructors run, so the watchdog thread is probably gone when a plugin DLL blocks. Covering that needs a test on Windows first, as a follow-up.rust/obs-frontend.Master is red on push runs from the windows-gnu oracle build (#4168, fix in #4191); that does not touch this path.
vpacher commentedon Nov 9, 2026
Claiming: the exit watchdog, PR #4309 (plan and decisions in my comment above).
frontend: End the process when exit() blocks after shutdown (obs-rust…
obs-exit-watchdog: Record which module brought in which libraries (ob…