mirror of
https://github.com/librespot-org/librespot.git
synced 2026-04-27 00:05:55 +03:00
[PR #1690] Add session recovery with automatic playback resume #1495
Labels
No labels
A-Alsa
SpotifyAPI
Tokio 1.0
audio
bug
can't reproduce
compilation
dependencies
duplicate
enhancement
good first issue
help wanted
high priority
imported
imported
invalid
new api
pull-request
question
reverse engineering
wiki
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/librespot#1495
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/librespot-org/librespot/pull/1690
Author: @Arneball
Created: 2/26/2026
Status: 🔄 Open
Base:
dev← Head:session-fix📝 Commits (1)
ed7ccbaAdd session recovery with automatic playback resume📊 Changes
6 files changed (+81 additions, -27 deletions)
View changed files
📝
connect/src/spirc.rs(+20 -5)📝
core/src/audio_key.rs(+9 -0)📝
core/src/session.rs(+6 -6)📝
examples/play_connect.rs(+12 -2)📝
playback/src/player.rs(+14 -10)📝
src/main.rs(+20 -4)📄 Description
When the TCP connection to Spotify access points drops due to network instability, the keep-alive timeout fires after ~80s and invalidates the session. The old spirc shuts down and a new Session + Spirc is created. However, three things went wrong:
Session ID mismatch: The new Session generated a fresh random UUID, so Spotify could not match it to the previous playback session. The automatic transfer in handle_connection_id_update failed because the cluster session_id did not match the new session_id.
Volume reset: ConnectConfig.initial_volume was set once at startup and reused on every reconnection. The new SpircTask initialized the mixer to this stale value instead of the users current volume, causing a jarring volume jump on reconnect.
Playback not resuming: The transfer state from Spotify always has is_paused=true after a disconnect, since the device went offline. handle_transfer used this to set start_playing=false, so the track loaded paused even though the user was actively listening.
Fixes:
Testing librespot session recovery via iptables
1. Find the AP connection
Example output:
Note the destination IP (
34.158.1.133) and source port (57572).2. Block the connection
Using the example values:
Blocking the specific source port is important — it kills the existing connection while allowing librespot to establish a new one on a different port.
3. Wait for reconnection
The keep-alive timeout fires after ~80 seconds. After that, the session is invalidated and librespot creates a new session + spirc. The audio buffer may sustain playback for another 1-2 minutes before the reconnection completes.
Monitor with:
Look for:
Shutdown: Invalidating session: keep-alive timeoutPreserved session_id across reconnectionstart_playing=true(if music was playing)4. Clean up iptables rules
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.