Skip to content

bug: linux-pulseaudio: a failed stream restart is never retried, and a stream that keeps failing restarts in a loop with no limit (follow-up of #378) #1029

Closed

Description

@rdoupe

Follow-up of #377 / #378, found in review of #378 (not an upstream report). When an Audio Input or Output Capture's own stream fails while the connection to the sound server stays up, #378 restarts it once. Two cases around that restart are not handled:

  1. The restart fails synchronously while the device is there and the server is connected (the stream cannot be created or connected, or the sample spec is invalid). Nothing retries it: the source stays silent until some device appears on the server or its settings change.
  2. The server keeps failing the restarted stream. Each failure restarts it at once, with no pause and no limit, so the source restarts in a loop on the UI thread for as long as the server keeps doing that. Since linux-pulseaudio: Give each capture stream a connection of its own #532 each restart also opens a new connection to the server.

Location

  • plugins/linux-pulseaudio/pulse-input.c line 519, pulse_stream_event_task(): the per-stream restart calls pulse_start_recording(data) and ignores its result.
  • Same file, line 557, pulse_stream_state_changed(): every failure of a stream queues another restart, and nothing counts them.
  • Compare line 413, pulse_restart_recording_task() (the server reconnection path from plugins: Reconnect Linux capture after PipeWire restarts #109): it retries a failed start with pulse_restart_should_retry() and pulse_call_later(), every 100 ms, up to 100 attempts.
  • plugins/linux-pulseaudio/pulse-reconnect.h line 69: "Each event leads to at most one start attempt, so a device that is gone for good is not polled." That is right for a missing device, but it also drops a start that failed for another reason.

Reproduced in 0.1.0-beta.20261014

The released AppImage (built from 9e2325e), headless: private PipeWire, WirePlumber and pipewire-pulse with no hardware, an Audio Input Capture on a virtual source, and a small LD_PRELOAD shim around pa_stream_new_with_proplist and pa_stream_connect_record that makes them fail on demand:

  • Stream killed (pw-cli destroy) and the next 3 stream creations set to fail: OBS logs "Stream from '...' failed, restarting it", then one "Unable to create stream", then nothing. No second attempt in 5 s. The source records again only after an unrelated device is added to the server. Same result in each of 3 recorded runs.
  • Every connected stream ended as soon as it is ready (a server that keeps failing it): 88 to 94 restarts in the first second and 1323 to 1398 in 15 s (two runs on an idle host), 19 and 395 in a run while the host was busy compiling. "Giving up" never appears, and each restart logs 6 lines. It stops only when the failure stops.

Current master has the same code (no change to plugins/linux-pulseaudio since 9e2325e).

Class

Silent audio loss (case 1), or a busy UI thread, a new server connection every few milliseconds and a growing log (case 2). No crash. Both need an unusual server or client state: a synchronous failure while the device is listed, or a server that rejects every new stream. No real-world trigger is known; #378 made things strictly better (before it, every per-stream failure was permanent). Likelihood is low, but the retry code that covers both is already there.

Proposed fix

Send per-stream restart failures and repeated stream failures through the existing counter. A start that fails while the device is there is retried every 100 ms. A failed stream is restarted at once the first time and after 100 ms after that. Both count towards the same 100-attempt limit, after which the source logs a warning and waits for a device to appear. A missing device is still waited for (not polled), and a lost server is still left to the reconnection. The counter resets when the stream delivers audio.

RED tests:

  • test_pulse_stream_restart (private PipeWire, no hardware, no display) wraps the same two calls and gains 3 cases: a failed restart is retried; a failing stream is restarted at least 100 ms apart, given up after the limit and started again when a device appears; a source destroyed while a retry is pending leaks nothing. 2 of 7 fail today. The 4 existing cases and the destroy control pass. It skips in CI (the Tier 2 image has no PipeWire), like the existing cases.
  • test_pulse_reconnect (no server; runs in CI): 4 cases for the new decision functions, added with the fix.

Activity

  1. rdoupe commented on Oct 16, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    This is a follow-up of our #378, so the fix stays inside plugins/linux-pulseaudio:

    1. RED: test_pulse_stream_restart makes stream creation and connection fail on demand. One case kills the stream and fails its next 3 creations: audio must come back within 3 s. One case fails every connected stream: restarts must be at least 100 ms apart, must stop after PULSE_RESTART_MAX_ATTEMPTS, and must start again when a device appears. A third case destroys a source while its retry is pending. Today the first two fail.
    2. GREEN: send both through the restart counter the reconnection path already uses. A failed start is retried every 100 ms. A failing stream is restarted at once the first time and after 100 ms after that, up to 100 attempts, then the source waits for a device. A missing device is still not polled. Two decision functions in pulse-reconnect.c get their own cases in test_pulse_reconnect, which runs in CI.
    3. Check the pause and the limit with the pause removed, run the end-to-end test 10 times in each lane, run full ctest in both lanes, and run the released AppImage case again on the fixed build. PR today.
  2. added
    claimed
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions