Skip to content

linux-pulseaudio: Restart a stream whose own connection was dropped - #1057

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pulse-stream-conn-drop
Oct 16, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pulse-stream-conn-drop

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1056

Builds on #1031 (merged): the restart goes through its retry, pause and limit.

What and why

An Audio Input or Output Capture on PulseAudio or PipeWire now records again when the server drops its stream's own connection. Before, it went silent for good, with nothing in the log. This came in with our #532 (each capture stream gets a server connection of its own). It was found in the release check of #1031 and reproduced in 0.1.0-beta.20261014.

Cause

In the release (0.1.0-beta.20261014 AppImage, private PipeWire + WirePlumber + pipewire-pulse, pw-cli destroy on the PipeWire client of the source's stream):

Build After its stream's connection is dropped
master before #532 (06ef6aa) "Lost the connection to the server", "Reconnected", "Started recording" within 10 ms
0.1.0-beta.20261014 AppImage no stream after 5 s, 0 restarts, no log line
current master (87582ae) the same
this branch (C lane build) "Stream from '...' failed, restarting it", a new stream within 5 s, 1 restart

Fix (all in plugins/linux-pulseaudio)

  • New pulse_connected() in pulse-wrapper.c: the shared connection is ready and not reconnecting. pulse_stream_state_changed() checks it instead of the stream's own context.
  • A stream whose own connection is gone is restarted like any failed stream, through linux-pulseaudio: Retry failed stream restarts with a pause and a limit #1031's retry, pause and limit. The new log line is "Stream from '...' failed, restarting it". pulse_stop_recording() frees the dead connection with the stream, as before.
  • A lost shared connection or a server restart is still left to the reconnection, which restarts each source once.

Not changed

  • When only the shared connection is dropped, the reconnection still restarts every source, even though their own connections are fine. Since linux-pulseaudio: Give each capture stream a connection of its own #532 that restart is not needed, but it does no harm: one restart per source, as the control case checks.
  • When the whole server goes away, the order in which libpulse reports the dead connections is not fixed. If a stream's failure is seen before the shared connection's, its restart finds no server ("Unable to get server info"). It changes nothing, and the reconnection replaces the stream as before. That happened in 1 of the 20 GREEN runs below, and the sources were still restarted once each. With the new check ignored (pulse_connected() returning true), 3 of 3 runs logged that line for both sources, and the sources were still restarted exactly once. So the guard against a double restart is the existing stale-stream and no-server handling, and the new check just keeps the log clean.
  • Only pipewire-pulse was tested, not a PulseAudio server. The drop is pw-cli destroy on the stream's client. On PulseAudio, pactl kill-client should reach the same state callback.

RED → GREEN

  • RED commit: dc23d14 test/cmocka: A dropped stream connection leaves its Pulse source silent (RED). test_pulse_stream_restart gains 5 cases. dropped_connection_restarts and repeated_connection_drops fail every run, 10/10 in each lane: "after the server dropped its stream's connection: 'capture A' produced no audio within 3000 ms" and "after its connection was dropped 1 times: ...". The 3 controls pass: source_destroyed_after_connection_drop, lost_shared_connection_restarts_once and server_restart_restarts_once. So do the 7 cases from linux-pulseaudio: Restart an input whose stream dies while connected #378 and linux-pulseaudio: Retry failed stream restarts with a pause and a limit #1031.
  • GREEN: a134807. 12/12 cases of test_pulse_stream_restart with ENABLE_RUST_LIBOBS OFF and ON, 10/10 runs alone in each lane, every case run against the private server (no skips), 34 s per run. test_pulse_reconnect 14/14 (unchanged; it needs no server and runs in CI). Full ctest at -j8 (private Xvfb, system libobs-opengl masked, TMPDIR unset): C lane 258/258, Rust lane 258/258. Skips: open_crashes_without_obs_core (in test_audio_io and test_video_io) in both lanes, as on master. One more per lane under load: test_startup_cycle_stress (C) and test_startup_alloc_stable (Rust), where obs_startup() failed. Both pass alone in both lanes, and neither is touched here. All PipeWire/Pulse tests ran. clang-format 22.1.3, gersemi 0.25.0 and ci/test_registration.py clean.
  • The release case again, on this branch's OBS build (C lane): cases A and B as with linux-pulseaudio: Retry failed stream restarts with a pause and a limit #1031 (the failed creations retried; 99 restarts, then "Giving up" once). Case C, the stream's connection dropped: restarted once, recording again within 5 s.
  • CI: as with linux-pulseaudio: Restart an input whose stream dies while connected #378 and linux-pulseaudio: Retry failed stream restarts with a pause and a limit #1031, the Tier 2 image has no PipeWire, WirePlumber or pipewire-pulse, so test_pulse_stream_restart skips there (exit 77); test_pulse_reconnect runs.

Checklist

  • Base is master (after linux-pulseaudio: Retry failed stream restarts with a pause and a limit #1031 merges; stacked on it until then)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): none
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not a port

AI note: Claude Code (Claude Opus 5.5) wrote the code, the tests, the commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

rdoupe and others added 2 commits October 16, 2026 05:29
…nt (RED)

Fails, every run, in both lanes (10 of 10 each):
dropped_connection_restarts ("after the server dropped its stream's
connection: 'capture A' produced no audio within 3000 ms") and
repeated_connection_drops ("after its connection was dropped 1 times:
'capture A' produced no audio within 3000 ms").

Follow-up of obs-rust#532, which gives each capture stream a server connection
of its own. When the server drops only that connection, the stream
fails with its context, and pulse_stream_state_changed() takes the
failed context for the lost shared connection: it leaves the restart
to the reconnection, which never comes because the shared connection
is fine. The source stays silent for good, and nothing is logged.

test_pulse_stream_restart gains five cases:
- the server drops the connection of one source's stream (pw-cli
  destroy on its client): audio must return within 3 s, and the other
  source must not restart;
- the connection is dropped 5 times, then twice in a row before the
  new stream delivers audio: audio returns each time, the source never
  gives up, and no connection is leaked;
- controls, which pass today: a source destroyed while its restart
  after a drop is pending leaks nothing; only the shared connection is
  dropped, and the reconnection restarts each source once; pipewire-
  pulse restarts, and each source is restarted once.

Refs obs-rust#1056.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since obs-rust#532 each capture stream has a server connection of its own
besides the shared one. When the server dropped only a stream's
connection, the stream failed with its context, and
pulse_stream_state_changed() took the failed context for the lost
shared connection: it left the restart to the reconnection, which
never came because the shared connection was fine. The source stayed
silent for good, with nothing in the log.

Check the shared connection instead (pulse_connected()). A stream whose
own connection is gone is restarted like any failed stream, through
the retry, pause and limit of obs-rust#1031. A lost shared connection or a
server restart is still left to the reconnection. If a stream's
failure is seen before the shared connection's, its restart finds no
server and does nothing, and the reconnection replaces the stream as
before, so each source is still restarted once.

test_pulse_stream_restart: 12 of 12, 10 of 10 runs in each lane.

Fixes obs-rust#1056.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 16, 2026 09:30
@zackees zackees added the ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak label Oct 16, 2026
@zackees
zackees enabled auto-merge October 16, 2026 09:34
@zackees
zackees added this pull request to the merge queue Oct 16, 2026
Merged via the queue into obs-rust:master with commit db87df6 Oct 16, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: linux-pulseaudio: a source stays silent for good when the server drops its stream's own connection (follow-up of #532)

2 participants