Repository navigation
Audio/Linux: retain partial writes and stop failed pumps - #1508
Open
sebastian-griego wants to merge 1 commit into
Open
sebastian-griego wants to merge 1 commit into
sebastian-griego wants to merge 1 commit into
Conversation
sebastian-griego
marked this pull request as ready for review
October 11, 2026 21:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Linux audio pump drops the unwritten part of a 256-frame chunk. With 512 queued frames, a first write of 64 frames delivers only 320 frames. It also retries terminal device errors because it ignores the result of
snd_pcm_recover.Keep an offset into the pending chunk until ALSA accepts all frames. Use nonblocking writes and bounded waits. Handle suspend recovery with separate resume and prepare calls so
Audio.closecan stop and join the pump. A zero write, failed recovery, or one second without progress stops the pump and stores its error. The nextAudio.writeorAudio.closejoins the pump, releases the device, prints the stored error, and exits with status 1. The existing Audio effect types stay the same. The one-second timeout is the error policy selected for this patch.Add a native Bend regression with ALSA's
nulloutput and controlled device return values. Positive writes reach the real ALSA library. The test checks all 255 first short-write lengths and 16 other cases. It verifies frame order, stereo channels, repeated partial writes, recovery, terminal errors, retry limits, and shutdown. Document the error policy inguide/EFFECTS.md.Validation:
-O3. All 271 cases pass. The default run takes 3.30 seconds.-O0. No sanitizer checks are disabled. AddressSanitizer leak detection is enabled.-O1with the three sanitizers. They cover full-ring drops, wraparound, empty-ring silence, and 50 concurrent pump lifecycles.audio_only_open,audio_only_write, andaudio_only_closetests pass in source and native lanes on Linux and macOS. The new test also passes source, JavaScript, and macOS native checks. JavaScript and macOS skip the Linux cases.git diff --checkpasses.Linux validation uses Debian 13 on aarch64, Clang 19.1.7, Bun 1.3.14, and ALSA 1.2.14. No physical ALSA device was tested. The cluster, performance, proof, and release gates were not run. Full sanitizer instrumentation at an optimized setting fails in the generated evaluator before the audio tests. The unchanged upstream program has the same pointer-offset diagnostic. The full sanitizer results above use the runtime's supported
-O0configuration.The ALSA documentation describes partial blocking writes and the return values from recovery: ALSA PCM API.