Skip to content

fix: give up on an output device that stops taking audio - #84

Merged
StuBehan merged 3 commits into
mainfrom
fix/stalled-output-device
Nov 24, 2026
Merged

StuBehan merged 3 commits into
mainfrom
fix/stalled-output-device

Conversation

@StuBehan

Copy link
Copy Markdown
Collaborator

Cmd+Opt+S in stack-nudge kept doing nothing, turned out the daemon was wedging and getting killed by the watchdog about 6 times a day. Sampled one before it went, the worker was sat in PortAudio's blocking write waiting for buffer space on my USB DAC, with no CoreAudio IO thread left to drain it. Blocking write never gives up so its 60s+ of nothing, then the watchdog kills the daemon and it reloads the model, and in the meantime the queue fills and everything else gets refused.

Now _write feeds the stream in slices of write_available and raises OutputStalledError if the device takes nothing for 5s. The stream gets aborted rather than stopped (stop waits for the queued audio to drain, which never happens) and the daemon resets PortAudio and replays the request once. A second stall goes down the normal playback error path, and the watchdog is still there for the stream stop deadlock. (No idea why the DAC stops pulling, the unified log has nothing for coreaudiod.)

Played a sentence through the DAC old vs new, same timing and the same single underflow at stream start, ~550 writes instead of 3 though. Couldn't get the DAC to stall on demand so the stall path is only covered by mocked tests. Downside is a replay starts the utterance from the top, so if it stalls partway you hear the start twice.

456 tests (10 new), ruff and mypy clean.

@StuBehan
StuBehan merged commit 086b108 into main Nov 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants