librespot-org / librespot

Open Source Spotify client library
MIT License
4.48k stars 542 forks source link

librespot / SPIRC crashed in the middle of the night #1241

Closed microfx closed 4 months ago

microfx commented 5 months ago

Describe the bug Saw that librespot is not available anymore this morning after having run for days without errors. I was sleeping and it crashed (no music was playing)

Log

Jan 16 05:02:32 librespot[1181]: [2024-01-16T04:02:32Z ERROR librespot_core::session] session lost connection to server 
Jan 16 05:02:32 librespot[1181]: [2024-01-16T04:02:32Z ERROR librespot_connect::spirc] remote update selected, but none received 
Jan 16 05:02:32 librespot[1181]: [2024-01-16T04:02:32Z WARN  librespot] Spirc shut down unexpectedly 
Jan 16 05:02:32 librespot[1181]: [2024-01-16T04:02:32Z WARN  librespot_core::apresolve] Failed to resolve all access points, using fallbacks 
Jan 16 05:02:32  librespot[1181]: [2024-01-16T04:02:32Z WARN  librespot_core::apresolve] Resolve access points error: Service unavailable { error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution } 
Jan 16 05:02:32  librespot[1181]: [2024-01-16T04:02:32Z INFO  librespot_core::session] Connecting to AP "ap.spotify.com:443" 
Jan 16 05:02:32  librespot[1181]: [2024-01-16T04:02:32Z ERROR librespot] could not initialize spirc: Unknown error { failed to lookup address information: Temporary failure in name resolution } 
Jan 16 05:02:32  systemd[1]: librespot.service: Main process exited, code=exited, status=1/FAILURE 
Jan 16 05:02:32  systemd[1]: librespot.service: Failed with result 'exit-code'. 
Jan 16 05:02:32  systemd[1]: librespot.service: Consumed 1h 13min 2.562s CPU time. 

When starting I get this - maybe is related?

librespot -v
[2024-01-16T10:00:25Z INFO  librespot] librespot 0.5.0-dev a245a3c (Built on 2023-12-23, Build ID: 0GbZXlzH, Profile: release)
[2024-01-16T10:00:25Z TRACE librespot] Command line argument(s):
[2024-01-16T10:00:25Z TRACE librespot]      v
[2024-01-16T10:00:25Z DEBUG librespot_core::session] new Session
[2024-01-16T10:00:25Z DEBUG librespot_discovery::server] Zeroconf server listening on 0.0.0.0:39675
*** WARNING *** The program 'librespot' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/blog/projects/avahi-compat.html>
[2024-01-16T10:00:25Z INFO  librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Log(60.0)
[2024-01-16T10:00:25Z DEBUG librespot_playback::player] new Player [0]
[2024-01-16T10:00:25Z INFO  librespot_playback::convert] Converting with ditherer: tpdf
[2024-01-16T10:00:25Z INFO  librespot_playback::audio_backend::rodio] Using Rodio sink with format S16 and cpal host: ALSA
[2024-01-16T10:00:25Z INFO  librespot_playback::audio_backend::rodio] Using audio device: default
[2024-01-16T10:00:25Z DEBUG librespot_playback::audio_backend::rodio] Rodio sink was created

Host (what you are running librespot on): OS: Raspbian GNU/Linux 11 (bullseye) aarch64 Kernel: Linux 6.1.69-v8-16k+ Raspberry Pi 5 8GB

librespot 0.5.0-dev a245a3c (Built on 2023-12-23, Build ID: 0GbZXlzH, Profile: release)

kingosticks commented 5 months ago

So it didn't really crash. Your network stopped working for a bit and librespot could not (immediately) reconnect, but rather than retrying, the session connection network failure causes spirc to return an error and the program to then exit. This does look like a bug in the connection retrying, librespot should handle spirc network-related errors differently as they might be recoverable.

microfx commented 5 months ago

Yeah... my ISP has tons of dropouts everyday... Can I maybe tell systemd to restart it? That's how mine looks:

[Unit]
Description=Librespot
After=sound.target
Wants=network-online.target
After=network.target network-online.target
After=jack.target

[Service]
LimitRTPRIO=95
LimitMEMLOCK=infinity
Environment=JACK_NO_AUDIO_RESERVATION=1
Environment=JACK_PROMISCUOUS_SERVER=jack
User=jack
Group=jack
Environment="DEVICE_NAME=hostname"
Environment="DEVICE_TYPE=speaker"
Environment="BITRATE=320"
Environment="CACHE_ARGS=--disable-audio-cache"
Environment="VOLUME_ARGS=--volume-ctrl linear --initial-volume 60"
Environment="DEVICE_TYPE=speaker"
#Environment="OUTPUT=hw:1,0"
Environment="OPTIONS=--username myusername --password mypassword --onevent /SCRIPTS/p5_speaker_onoff.sh"
ExecStartPre=/bin/sleep 4
ExecStart=/usr/bin/librespot --name ${DEVICE_NAME} --device-type ${DEVICE_TYPE} --bitrate ${BITRATE} $CACHE_ARGS $VOLUME_ARGS $OPTIONS --backend rodiojack
[Install]
WantedBy=multi-user.target
microfx commented 5 months ago

I'll add

Restart=on-failure
RestartSec=5s

and report back if that fixed it.

microfx commented 4 months ago

I guess it's fixed. Still a few other weird issues – I will look into those now. Thx!