Skip to content

Fix latency error check in pulse_delay() - #67

Closed
argothiel wants to merge 1 commit into
alsa-project:masterfrom
argothiel:latency-error-check
Closed

argothiel wants to merge 1 commit into
alsa-project:masterfrom
argothiel:latency-error-check

Conversation

@argothiel

Copy link
Copy Markdown
Contributor

There is an issue with pulse_delay() which calls pa_stream_get_latency(). PulseAudio documents that this function returns -PA_ERR_NODATA when timing information is not available yet. The ALSA Pulse plugin compares the result against positive PA_ERR_NODATA; it therefore treats that temporary condition as an unrelated failure and returns -EIO.

Change PA_ERR_NODATA to -PA_ERR_NODATA in the comparison to not miss that branch.

Fixes #65.

@ZmoleCristian

Copy link
Copy Markdown

Independent confirmation of the impact and the proposed fix. We encountered repeated voice-session termination in a Linux application using CPAL's ALSA backend through the PulseAudio ALSA plugin. The native error was snd_pcm_avail_delay: I/O error (5), observed both shortly after opening playback and after reopening the output stream. For the user this repeatedly interrupted voice interaction.

We independently arrived at the identical one-line correction in this PR and tested the actual pulse_delay() function with controlled dependency stubs: the original code returns false -EIO for -PA_ERR_NODATA; with the correction, all 101 cases (0 through 100 consecutive timing-unavailable responses before success) pass. Other errors and a disconnected stream still propagate as errors. These are deterministic function-level tests, not 101 hardware runs.

We also installed a privately rebuilt plugin with this change. The user reports no further interruptions in the current observation period; longer real-world validation is ongoing. Our historical ALSA logs do not expose the underlying PulseAudio return code, so we cannot attribute every past EIO to this branch.

The positive comparison appears to have been introduced in c2456f2 (2008-09-03), when the wait-for-timing loop was added. Before that, the function already returned EIO on any latency-query error, so this dates the faulty comparison rather than establishing the first occurrence of the symptom.

This has a substantial user-visible impact in applications that treat the error as fatal. Please consider prioritizing review of this fix. Thank you for preparing it.

@gmelikov

gmelikov commented Oct 1, 2026

Copy link
Copy Markdown

Tested this exact patch locally. The reproducer failed with EIO in 3/3 unpatched runs and succeeded in 3/3 patched runs.

My case is - pactl load-module module-native-protocol-tcp listen=127.0.0.1 port=4713 auth-anonymous=1 on laptop and port-forward it via SSH.

@argothiel

Copy link
Copy Markdown
Contributor Author

@perexg @tiwai

Could you please advise who can approve and merge it?

@argothiel

Copy link
Copy Markdown
Contributor Author

@i-garrison @poettering
Maybe you could help? It's about a one-line fix in the PulseAudio plugin. Two users have independently confirmed it resolves the issue.

@i-garrison

Copy link
Copy Markdown
Contributor

I can confirm that checking for negative value of error constant is valid fix indeed!

@perexg could you please merge this? Thank you!

@fayerman-source

fayerman-source commented Oct 14, 2026 •

Copy link
Copy Markdown

I tried the change on my WSL2 setup. The installed plugin had the positive-16 comparison; silent snd_pcm_avail_delay probe failed three times with the installed plugin, then passed three out of three using a copy with the comparison changed to negative 16. With that copy in asoundrc, playback and capture opened. The first Codex slash voice still failed at OpenDevices/25; later it worked. I can't explain that first failure, but wanted to add another WSL2 repro.

@argothiel

Copy link
Copy Markdown
Contributor Author

Is @perexg the only one with merging rights?

@perexg

perexg commented Oct 15, 2026

Copy link
Copy Markdown
Member

Apologize, busy with other things. The signed-off-by / commit author e-mail is anonymous.

@perexg perexg closed this in bd8eaa1 Oct 15, 2026
@perexg perexg reopened this Oct 15, 2026
@perexg

perexg commented Oct 15, 2026

Copy link
Copy Markdown
Member

Sorry, wrong push. The bd8eaa1 was not applied.

@github-actions github-actions Bot added the signed off by Missing Signed-off-by: line. label Oct 15, 2026
There is an issue with `pulse_delay()` which calls
`pa_stream_get_latency()`. PulseAudio documents that this function
returns `-PA_ERR_NODATA` when timing information is not available yet.
The ALSA Pulse plugin compares the result against positive
`PA_ERR_NODATA`; it therefore treats that temporary condition as an
unrelated failure and returns `-EIO`.

Change `PA_ERR_NODATA` to `-PA_ERR_NODATA` in the comparison to not miss
that branch.

Fixes alsa-project#65.

Signed-off-by: argothiel <argothiel_alsa@interia.pl>
@argothiel
argothiel force-pushed the latency-error-check branch from cef4685 to 022c569 Compare October 15, 2026 13:32
@github-actions github-actions Bot removed the signed off by Missing Signed-off-by: line. label Oct 15, 2026
@argothiel

argothiel commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

@perexg No worries, I just wanted to make sure if we have the right person! 😊

The e-mail sign-off address has been corrected.

@perexg perexg closed this in 811c2ce Oct 15, 2026
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.

ALSA Pulse plugin returns -EIO from snd_pcm_avail_delay() in case of -PA_ERR_NODATA

6 participants