[GH-ISSUE #1506] librespot does not release ALSA device after Spotify Connect stream finishes #680

Open
opened 2026-02-27 19:31:55 +03:00 by kerem · 11 comments
Owner

Originally created by @frialey63 on GitHub (Jun 7, 2025).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/1506

Version

librespot 0.6.0 VERGEN_IDEMPOTENT_OUTPUT (Built on 2025-05-31, Build ID: 8j6X3B4v, Profile: release)

How to reproduce

When librespot has finished playing a stream using Spotify Connect, I then attempt to play a local file using mpd (running on the same sever as librespot and configured to output to the same ALSA device) but no sound is heard.

Command

usr/bin/librespot --name librespot --cache /tmp/librespot --bitrate 320 --autoplay off --disable-gapless --enable-volume-normalisation --normalisation-gain-type track --backend rodio --device plughw:CARD=Loopback,DEV=1 --format S16 -mixer softvol --volume-ctrl fixed --initial-volume 100 --dither none

Host

Linux pi 6.6.51+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt3 (2024-10-08) aarch64 GNU/Linux

Additional context

If I disable librespot and enable librespot-player (Java) then this operation works as expected. The librespot-player has a configurable parameter releaseLineDelay which demonstrates that it is designed to release the ALSA device after it has finished playing.

Originally created by @frialey63 on GitHub (Jun 7, 2025). Original GitHub issue: https://github.com/librespot-org/librespot/issues/1506 ### Version librespot 0.6.0 VERGEN_IDEMPOTENT_OUTPUT (Built on 2025-05-31, Build ID: 8j6X3B4v, Profile: release) ### How to reproduce When librespot has finished playing a stream using Spotify Connect, I then attempt to play a local file using mpd (running on the same sever as librespot and configured to output to the same ALSA device) but no sound is heard. ### Command ``` usr/bin/librespot --name librespot --cache /tmp/librespot --bitrate 320 --autoplay off --disable-gapless --enable-volume-normalisation --normalisation-gain-type track --backend rodio --device plughw:CARD=Loopback,DEV=1 --format S16 -mixer softvol --volume-ctrl fixed --initial-volume 100 --dither none ``` ### Host Linux pi 6.6.51+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt3 (2024-10-08) aarch64 GNU/Linux ### Additional context If I disable librespot and enable librespot-player (Java) then this operation works as expected. The librespot-player has a configurable parameter `releaseLineDelay` which demonstrates that it is designed to release the ALSA device after it has finished playing.
Author
Owner

@photovoltex commented on GitHub (Jun 7, 2025):

This sounds quite similar to the observation in #1500. Could you give https://github.com/photovoltex/librespot/tree/reduced-sink-usage a try? The TL;DR; would be that we don't close the audio sink while we don't play any audio. We could also add a similar parameter to the binary and the delay after stopping playback. But the branch previously mentioned is just a poc if it would fix the issue. Thanks in advance for the testing :)

<!-- gh-comment-id:2952593448 --> @photovoltex commented on GitHub (Jun 7, 2025): This sounds quite similar to the observation in #1500. Could you give https://github.com/photovoltex/librespot/tree/reduced-sink-usage a try? The TL;DR; would be that we don't close the audio sink while we don't play any audio. We could also add a similar parameter to the binary and the delay after stopping playback. But the branch previously mentioned is just a poc if it would fix the issue. Thanks in advance for the testing :)
Author
Owner

@frialey63 commented on GitHub (Jun 7, 2025):

I have built the release of librespot from branch https://github.com/photovoltex/librespot/tree/reduced-sink-usage and when run with the same options it encounters the same problem. While librespot is running Spotify streams play fine but when a stream is finished it is not possible to switch to mpd and play (hear) a local file. I have waited 30secs and 60secs after the stream was finished. In order to play and hear the local files via mpd it is necessary to stop the librespot process.

This problem does not occur when using librespot-player, it is possible to switch between playing Spotify streams and local files from mpd while these two services are both up and running continuously. (Subject only to waiting for releaseLineDelay after a stream has finished.)

<!-- gh-comment-id:2953040910 --> @frialey63 commented on GitHub (Jun 7, 2025): I have built the release of librespot from branch `https://github.com/photovoltex/librespot/tree/reduced-sink-usage` and when run with the same options it encounters the same problem. While librespot is running Spotify streams play fine but when a stream is finished it is not possible to switch to mpd and play (hear) a local file. I have waited 30secs and 60secs after the stream was finished. In order to play and hear the local files via mpd it is necessary to stop the librespot process. This problem does not occur when using librespot-player, it is possible to switch between playing Spotify streams and local files from mpd while these two services are both up and running continuously. (Subject only to waiting for `releaseLineDelay` after a stream has finished.)
Author
Owner

@photovoltex commented on GitHub (Jun 8, 2025):

Thanks for the quick testing. A bummer that it isn't such an easy fix. I will look into it when I'm back home. The best case would be to just carry over what librespot-java does, but could be a bit more tricky depending on the infrastructural differences.

<!-- gh-comment-id:2953736821 --> @photovoltex commented on GitHub (Jun 8, 2025): Thanks for the quick testing. A bummer that it isn't such an easy fix. I will look into it when I'm back home. The best case would be to just carry over what librespot-java does, but could be a bit more tricky depending on the infrastructural differences.
Author
Owner

@kdistin commented on GitHub (Jun 21, 2025):

I have librespot and mpd running on the same server.
I do not see this problem. As soon as I stop librespot playback I can play a local file with mpd.
My librespot options are:
--backend alsa --bitrate 320 --device hw:0,0 --device-type computer --disable-audio-cache --alsa-mixer-control Master --initial-volume 100

<!-- gh-comment-id:2993689499 --> @kdistin commented on GitHub (Jun 21, 2025): I have librespot and mpd running on the same server. I do not see this problem. As soon as I stop librespot playback I can play a local file with mpd. My librespot options are: `--backend alsa --bitrate 320 --device hw:0,0 --device-type computer --disable-audio-cache --alsa-mixer-control Master --initial-volume 100`
Author
Owner

@frialey63 commented on GitHub (Jun 22, 2025):

OK, looking at your options I see that you are using the alsa backend whereas I have been using the rodio backend because this seems to the preferred (default) backend for librespot. When I get time, I will do a test with alsa and report back.

<!-- gh-comment-id:2994121710 --> @frialey63 commented on GitHub (Jun 22, 2025): OK, looking at your options I see that you are using the `alsa` backend whereas I have been using the `rodio` backend because this seems to the preferred (default) backend for librespot. When I get time, I will do a test with `alsa` and report back.
Author
Owner

@spockfish commented on GitHub (Aug 25, 2025):

I can confirm having the same issue.

<!-- gh-comment-id:3219994141 --> @spockfish commented on GitHub (Aug 25, 2025): I can confirm having the same issue.
Author
Owner

@roderickvd commented on GitHub (Aug 25, 2025):

Does #1552 help?

<!-- gh-comment-id:3221696680 --> @roderickvd commented on GitHub (Aug 25, 2025): Does #1552 help?
Author
Owner

@spockfish commented on GitHub (Aug 26, 2025):

@roderickvd Yes! I can confirm that the patch from #1552 fixes this issue as well.

Thanks!

<!-- gh-comment-id:3224353111 --> @spockfish commented on GitHub (Aug 26, 2025): @roderickvd Yes! I can confirm that the patch from #1552 fixes this issue as well. Thanks!
Author
Owner

@kingosticks commented on GitHub (Aug 26, 2025):

Was #1552 supposed to have this side effect?! From a quick glance it doesn't look related! Given I don't understand the fix, can someone explain when does librespot now release the sink? After any track finishes, or only after all the tracks in the current context finish?

<!-- gh-comment-id:3224387772 --> @kingosticks commented on GitHub (Aug 26, 2025): Was #1552 supposed to have this side effect?! From a quick glance it doesn't look related! Given I don't understand the fix, can someone explain when does librespot now release the sink? After any track finishes, or only after all the tracks in the current context finish?
Author
Owner

@roderickvd commented on GitHub (Aug 26, 2025):

😅 it was a hunch that the queue would be cleared and playback stopped when we properly handle a disconnect event. And so it did…

<!-- gh-comment-id:3224423627 --> @roderickvd commented on GitHub (Aug 26, 2025): 😅 it was a hunch that the queue would be cleared and playback stopped when we properly handle a disconnect event. And so it did…
Author
Owner

@photovoltex commented on GitHub (Aug 26, 2025):

From a quick glance it doesn't look related!

Understandably, the underlying issue is here:
https://github.com/librespot-org/librespot/blob/dev/connect/src/spirc.rs#L901

handle_disconnect early returns on a error. Tho previously this didn't had the option to return an error, so I'm also surprised this should be resolved now.

<!-- gh-comment-id:3224549049 --> @photovoltex commented on GitHub (Aug 26, 2025): > From a quick glance it doesn't look related! Understandably, the underlying issue is here: https://github.com/librespot-org/librespot/blob/dev/connect/src/spirc.rs#L901 `handle_disconnect` early returns on a error. Tho previously this didn't had the option to return an error, so I'm also surprised this should be resolved now.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#680
No description provided.