Skip to content

libobs: Finish the stop of an output stopped while reconnecting - #3935

Merged
vpacher merged 2 commits into
masterfrom
fix/3933-reconnect-stop
Nov 7, 2026
Merged

vpacher merged 2 commits into
masterfrom
fix/3933-reconnect-stop

Conversation

@vpacher

@vpacher vpacher commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Problem

A stream through the FFmpeg muxer to a server that does not answer (for example an SRT address, from OBS or from a Source Record filter) fails to connect, and libobs waits to reconnect. A stop in that wait goes to obs_output_actual_stop(): it resets the stopping event, joins the reconnect thread and calls the output's stop. ffmpeg_mux_stop() only sets a flag, because the muxer ends a stop with its next packet. The data capture ended with the failure, so no packet comes. Nothing signals the stopping event, and obs_output_destroy() waits on it forever: OBS does not exit.

Upstream OBS 33.0.1 and upstream master have the same code in obs_output_actual_stop() and ffmpeg_mux_stop(). The new test hangs with upstream 33.0.1 too.

Reproduced in the app on Linux (Arch, obs-studio-rust-git r35):

  • OBS stream to srt://10.255.255.1:9000?mode=caller, "Stop Streaming" while it waits to reconnect, then quit: hangs. The main thread waits in obs_output_release() -> obs_output_destroy() -> os_event_wait(stopping_event).
  • A Source Record filter that streams to the same address: hangs at every quit (2 of 2), because the filter stops its output when it is destroyed.
  • The same stream not stopped before the quit, or stopped during a connect attempt: quits in 0.2 s.

Change

obs_output_actual_stop() now finishes the stop of an output that was reconnecting when the output's stop left it stopping and inactive: it signals "stop" and the stopping event, as it already does for a delayed output. An output whose stop ends the stop itself (rtmp_output signals its stop when it is not active) is left alone, so "stop" comes once.

Tests

  • RED, e51b60d (test/cmocka/test_output_stop_while_reconnecting.c, new): starts an output, fails it with OBS_OUTPUT_DISCONNECTED and a long retry delay, stops it while it waits to reconnect and releases it, in a child process with a watchdog. Three cases: a stop that only sets a flag (ffmpeg_muxer), a stop that signals itself (rtmp_output), and a stop of a connected output (control). Each must stop, be destroyed and signal "stop" once.
  • GREEN, b6baa23.
Hybrid libobs C libobs Upstream 33.0.1
Without the change flag stop hangs (watchdog), 2 others pass same same
With the change 3 of 3 pass 3 of 3 pass not applicable

test_output_stop_without_packets (#3764) still passes with both builds. Built on Linux (Debian 13) from this branch, libobs and libobs-opengl, run under Xvfb.

Local gate (b6baa23, stamped): lint, dylint, rust-test, cross and tier2-linux passed in 7 min; Tier 2 ran the new test in both modes (4.1 s C, 4.2 s hybrid).

Tiers: Tier 2 is the new cmocka test (hybrid and C reference). No Rust code changes, so Tier 1 and Tier 3 do not apply. Test cost: about 3 s per case (1 s of output, then the stop and release), one child process per case, no own threads in the test.

In the app (Arch, obs-studio-rust-git r35 rebuilt with only this change, same machine and harness as the reproduction):

Case r35 r35 with the change
OBS stream to the SRT address, "Stop Streaming" during the reconnect wait, quit hangs quits in 0.2 s (4 of 4 runs)
Source Record streaming to the SRT address, quit hangs (2 of 2) quits in 1.0-1.1 s (2 of 2)
Source Record recording MKV (control) quits in 0.9 s quits in 1.0-1.1 s

The logs show the stop right after "Reconnecting in 2.00 seconds..", with no connect attempt in between, and one "Streaming Stop".

Fixes #3933. Refs #3739: found while investigating it; the leftover obs-studio-rust-ffmpeg-mux reported there is probably a different bug, so that issue stays open.

🤖 Generated with Claude Code

vpacher and others added 2 commits November 7, 2026 20:48
A stream through the FFmpeg muxer to a server that does not answer (an SRT
address, from OBS or from source-record) fails to connect, and libobs
waits to reconnect. A stop in that wait resets the stopping event and
calls ffmpeg_mux_stop(), which only sets a flag: the stop ends with the
next packet, and an output whose data capture has ended gets none.
Nothing signals the stopping event, and obs_output_destroy() waits on it
forever: OBS does not exit.

The test fails a started output with OBS_OUTPUT_DISCONNECTED and a long
retry delay, stops it while it waits to reconnect, and releases it, in a
child process with a watchdog. RED with production 6d29998 (hybrid) and
upstream OBS 33.0.1: the stop that only sets a flag hangs; a stop that
signals itself when the output is not active (rtmp_output) and a stop of a
connected output finish, each with one "stop" signal.

Refs #3933, #3739

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A stream through the FFmpeg muxer to a server that does not answer (an
SRT address, from OBS or from source-record) fails to connect, and libobs
waits to reconnect. A stop in that wait resets the stopping event, joins
the reconnect thread and calls the output's stop. ffmpeg_mux_stop() only
sets a flag: the stop ends with the next packet, and an output whose data
capture ended with the failure gets none. Nothing signals the stopping
event, and obs_output_destroy() waits on it forever: OBS does not exit.

obs_output_actual_stop() now finishes the stop of an output that was
reconnecting when the output's stop left it stopping and inactive: it
signals "stop" and the stopping event, as it already does for a delayed
output. An output whose stop ends the stop itself (rtmp_output signals
its stop when it is not active) is left alone, so "stop" comes once.

test_output_stop_while_reconnecting: hybrid and C libobs, built from this
branch on Linux. Without the change the stop that only sets a flag hangs
(watchdog); with it all three cases stop, are destroyed and signal "stop"
once. test_output_stop_without_packets still passes with both.

Refs #3933, #3739

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=f8b673e69d66e95db03a750e3517245ed6c32f64 secs=422 lanes=lint:run,dylint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1794081347,"gate":"rust/all/fmt","host":"linux-x86_64","key":"735588b5d71e8b893e7af685018c8c339b33f2b65fd3b67f9b03cb0dcc58c198","lane":"lint","parents":["e51b60dbf5d2b3f8f0bd6697e22b9e28d3a77a6c"],"secs":112,"stamp":"48efa82b313263408055abcdb98dddfc","tree":"f8b673e69d66e95db03a750e3517245ed6c32f64","v":1,"via":"run"}
Ci-Attestation: {"at":1794081347,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"735588b5d71e8b893e7af685018c8c339b33f2b65fd3b67f9b03cb0dcc58c198","lane":"lint","parents":["e51b60dbf5d2b3f8f0bd6697e22b9e28d3a77a6c"],"secs":112,"stamp":"c1ecd32182e2b5b6b30a418ad634aa51","tree":"f8b673e69d66e95db03a750e3517245ed6c32f64","v":1,"via":"run"}
Ci-Attestation: {"at":1794081347,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"1df69adc6b5088f88555479c0b91765f5d3ab4c786e09ee5b88e165cafc02eb7","lane":"rust-test","parents":["e51b60dbf5d2b3f8f0bd6697e22b9e28d3a77a6c"],"secs":157,"stamp":"a311dd3819aac077de84a057a72984e5","tree":"f8b673e69d66e95db03a750e3517245ed6c32f64","v":1,"via":"run"}
Ci-Attestation: {"at":1794081347,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"067317ea1cd956382c44e69a59226b66fe968011b6a987809467b7981747c9c0","lane":"cross","parents":["e51b60dbf5d2b3f8f0bd6697e22b9e28d3a77a6c"],"secs":147,"stamp":"5dd52b818896add749fb3455b6b75ce1","tree":"f8b673e69d66e95db03a750e3517245ed6c32f64","v":1,"via":"run"}
Ci-Attestation: {"at":1794081347,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"067317ea1cd956382c44e69a59226b66fe968011b6a987809467b7981747c9c0","lane":"cross","parents":["e51b60dbf5d2b3f8f0bd6697e22b9e28d3a77a6c"],"secs":147,"stamp":"ed431a0aac946f42f1a279e57fa7bde8","tree":"f8b673e69d66e95db03a750e3517245ed6c32f64","v":1,"via":"run"}
Ci-Attestation: {"at":1794081347,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"067317ea1cd956382c44e69a59226b66fe968011b6a987809467b7981747c9c0","lane":"cross","parents":["e51b60dbf5d2b3f8f0bd6697e22b9e28d3a77a6c"],"secs":147,"stamp":"c793299a76e88682e714617c2178bc1a","tree":"f8b673e69d66e95db03a750e3517245ed6c32f64","v":1,"via":"run"}
Ci-Attestation: {"at":1794081347,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"067317ea1cd956382c44e69a59226b66fe968011b6a987809467b7981747c9c0","lane":"cross","parents":["e51b60dbf5d2b3f8f0bd6697e22b9e28d3a77a6c"],"secs":147,"stamp":"9f11569beec351c665b77c08bfd38dea","tree":"f8b673e69d66e95db03a750e3517245ed6c32f64","v":1,"via":"run"}
Ci-Attestation: {"at":1794081347,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"59bf5958ee73f27151231db6187c9222656d8eb994e9b9222e331d45031ae05b","lane":"tier2-linux","parents":["e51b60dbf5d2b3f8f0bd6697e22b9e28d3a77a6c"],"secs":410,"stamp":"06b1a958fbce2db34b8a14e084e65b27","tree":"f8b673e69d66e95db03a750e3517245ed6c32f64","v":1,"via":"run"}
@vpacher
vpacher marked this pull request as ready for review November 7, 2026 20:08
@vpacher
vpacher requested a review from zackees as a code owner November 7, 2026 20:08
@vpacher
vpacher enabled auto-merge November 7, 2026 20:08
@vpacher
vpacher added this pull request to the merge queue Nov 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 7, 2026
@vpacher
vpacher added this pull request to the merge queue Nov 7, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this to In merge queue in obs-rust Multiview Nov 7, 2026
Merged via the queue into master with commit a12b6a3 Nov 7, 2026
41 checks passed
@vpacher
vpacher deleted the fix/3933-reconnect-stop branch November 7, 2026 22:22
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In merge queue to Done in obs-rust Multiview Nov 8, 2026
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.

bug: libobs: OBS hangs on exit after a stream was stopped while it waited to reconnect

1 participant