Skip to content

frontend: Recording shutdown waits for the stop signal instead of polling the UI thread (#1283) - #1342

Merged
zackees merged 3 commits into
masterfrom
fix/1283-recording-shutdown-async
Oct 17, 2026
Merged

zackees merged 3 commits into
masterfrom
fix/1283-recording-shutdown-async

Conversation

@zackees

@zackees zackees commented Oct 17, 2026

Copy link
Copy Markdown
Member

Refs #1283 (parent #1273)

Problem

StopRecordingForShutdown() (frontend/widgets/RecordingShutdown.hpp) waited for the recording to stop by sleeping 10 ms at a time on the UI thread, up to 5 s, so quitting while recording froze the window for the whole wait.

Callers

Only one: OBSBasic::closeWindow() (frontend/widgets/OBSBasic.cpp.hpp), before it waits on its worker threads and later destroys the outputs (outputHandler.reset()). It needs the recording finalized before it continues, so the wait stays synchronous for this caller. Profile and scene-collection switches do not use this path. The existing test_recording_shutdown (Tier 2, real libobs output) calls the 2-arg overload, which keeps the old polling wait for non-UI callers.

Design

  • StopRecordingForShutdown(handler, timeout_ms, wait) is a new overload: graceful stop, then wait(timeout_ms), then a forced stop if it did not stop. The timeout (5000 ms) and the timeout behaviour are unchanged.
  • WaitForOutputToStop(signal_handler, timeout_ms, active) (new header-only RecordingShutdownWait.hpp, added to the frontend-widgets PCH) runs a nested QEventLoop with ExcludeUserInputEvents, because the window is closing. The loop ends on:
    • the output's deactivate signal, or on stop once active() is false. libobs signals stop while the encoders are still flushing and deactivate just before it clears active, so this matches the old "wait until inactive" condition. An output that never began capturing sends only stop and is already inactive.
    • or a single-shot Qt::PreciseTimer at the timeout.
  • The libobs callbacks run on libobs threads. They only set an atomic and queue the check to the UI thread with QMetaObject::invokeMethod(..., Qt::QueuedConnection). libobs holds the signal mutex while it runs callbacks, so after signal_handler_disconnect no callback is still running. Checks still queued are dropped when the receiver QObject is destroyed.
  • The handlers are connected before the first active() check, so a stop that comes before the wait starts is not missed.
  • It is a QEventLoop rather than a fully async continuation because the rest of closeWindow() (thread waits, saving, then destroying the outputs) has to run after the recording is finalized. Splitting closeWindow in two would change shutdown ordering for every other step.

Test (new, no existing test edited)

test/cmocka/test_recording_shutdown_wait.cpp + tests.d/test_recording_shutdown_wait.cmake: Qt-linked (QtCore only, no display), so ci_scope selects the Qt lane (ci/linux_qt_frontend.sh builds and runs every tests.d fragment that finds Qt6). A fake output signals stop and then deactivate from another thread after 200 ms:

  • the wait ends after the signal (≥150 ms and below the timeout), and a QTimer posted to the UI loop fires during the wait
  • with no stop, the wait ends at the timeout (300 ms; asserts ≥250 and <3000) and the posted timer still fires
  • an output that is already inactive returns at once
  • StopRecordingForShutdown with this wait: a stuck recording is force-stopped once, and one that stops is not

RED (9895d06, WaitForOutputToStop = the old polling loop)

stopped 1 after 221 ms, posted timer fired 0 (while waiting 0)
[  FAILED  ] test_wait_ends_on_stop_and_keeps_ui_running
no stop: returned 0 after 302 ms, posted timer fired 0
[  FAILED  ] test_wait_times_out_without_stop

GREEN (922f0a8)

stopped 1 after 220 ms, posted timer fired 1 (while waiting 1)
no stop: returned 0 after 300 ms, posted timer fired 1
[  PASSED  ] 4 test(s).

I ran these locally by building the test by hand against the Nix QtCore 6.11, cmocka 2.0 and libobs's callback/util sources, not through CMake.

Only the Qt CI lane verifies

  • the CMake registration of the new test and its run against the prebuilt Qt
  • that the closeWindow() change and the PCH include compile in the real obs-studio frontend target

I did not run the real app here: no manual quit-while-recording check. Hence "Refs" and not "Fixes".

./lint passes. I added a docs/features.md ledger line (Fixed upstream bugs → Scenes and UI).

@zackees
zackees enabled auto-merge October 17, 2026 21:31
@zackees
zackees added this pull request to the merge queue Oct 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 17, 2026
@zackees
zackees enabled auto-merge October 17, 2026 21:55
…unning (RED, #1283)

Adds test_recording_shutdown_wait (Qt-linked cmocka, QtCore only): a fake
output signals stop/deactivate from another thread after 200 ms; the wait
must end after it, a timer posted to the UI event loop must fire during the
wait, and with no stop the timeout still ends the wait and force-stops.

WaitForOutputToStop() is introduced with the current sleep-polling
behaviour, so the two event-loop cases fail.

Refs #1283
…ling the UI thread (GREEN, #1283)

closeWindow() needs the recording finalized before it destroys the outputs,
so the wait stays synchronous for it, but WaitForOutputToStop() now runs a
nested QEventLoop (user input excluded) that ends on the output's
"deactivate" signal (or "stop" once inactive), hopped to the UI thread
with a queued invocation, or on a single-shot PreciseTimer at the unchanged
5 s timeout, after which the recording is force-stopped as before.

Refs #1283
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.

1 participant