librespot: Timeout? Librespot-enabled device disappears from Spotify device list after a while

My RaspberryPi with Librespot has been running for a couple hours now and, earlier today, everything was working fine and I could listen to songs on Spotify through the speakers connected to the RPi. At some point this afternoon I paused the music, though, and now, hours later, I wanted to unpause it. However, Spotify didn’t list my RPi among the available devices anymore.

So I ssh’d into the RPi and took a look at the logs. They seemed fine:

[…]
INFO:librespot_playback::player: Loading track "XY" with Spotify URI "spotify:track:4H6qtMPzKYRCsf7bT2DcBP"
INFO:librespot_playback::player: Track "XY" loaded
INFO:librespot::player_event_handler: Running ["/opt/musicbox/mpc_stop.sh"] with environment variables {"OLD_TRACK_ID": "foo", "TRACK_ID": "bar", "PLAYER_EVENT": "change"}
INFO:librespot::player_event_handler: Running ["/opt/musicbox/mpc_stop.sh"] with environment variables {"PLAYER_EVENT": "stop", "TRACK_ID": "bla"}

I then restarted librespot through service librestart stop/start and this fixed the issue—the RPi reappeared in Spotify’s device list. Meanwhile, the logs are:

INFO:librespot: librespot 1e69138 (2018-05-18). Built on 2018-05-29. Build ID: Ptc4Ggyb
INFO:librespot_core::session: Connecting to AP "gew1-accesspoint-b-psjr.ap.spotify.com:4070"
INFO:librespot_core::session: Authenticated as "ABCDEFG" !
INFO:librespot_playback::audio_backend::alsa: Using alsa sink
INFO:librespot_core::session: Country: "CO"

So it seems that there is some kind of timeout causing Spotify to forget about a device with Librespot after a while?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 5
  • Comments: 30 (12 by maintainers)

Most upvoted comments

This happens for me with every project I’ve used based on this library (volumio, raspotify, etc.) Even if librespot can’t handle reconnections yet, if we could at least have it crash it would be easier to programmatically restart it.

Still have this issue (running on latest build)- It happens randomly - sometimes librespot runs for ages - sometimes a few times a week. Tonight it happened on both my Pi’s - connected on 2 different locations and networks. (same city thou) It must be something with the handshake with the server that fails. If the connection between librespot and the Spotify server is unavailable at that exact time it fails and panic.

librespot d2cadec (2018-11-19). Built on 2018-12-14. Build ID: ITqtjWoj 
...
DEBUG:librespot_core::session: Session[0] strong=3 weak=4
thread 'main' panicked at 'connection closed', libcore/option.rs:1000:5
stack backtrace:
   0:   0x8af167 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h63a67ac893ab31ec                                                                                                           
                       at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49                                                                                                                                   
   1:   0x89e423 - std::sys_common::backtrace::print::ha8f26509b9ff262c                                                                                                                                   
                       at libstd/sys_common/backtrace.rs:71                                                                                                                                               
                       at libstd/sys_common/backtrace.rs:59                                                                                                                                               
   2:   0x89bca7 - std::panicking::default_hook::{{closure}}::hd7e08be4e57c3548                                                                                                                           
                       at libstd/panicking.rs:211                                                                                                                                                         
   3:   0x89b91f - std::panicking::default_hook::h216d888df769ef77                                                                                                                                        
                       at libstd/panicking.rs:227                                                                                                                                                         
   4:   0x89c3cf - std::panicking::rust_panic_with_hook::h7d39a7695d8da98f                                                                                                                                
                       at libstd/panicking.rs:477                                                                                                                                                         
   5:   0x89bf93 - std::panicking::continue_panic_fmt::ha287897123d4a956                                                                                                                                  
                       at libstd/panicking.rs:391                                                                                                                                                         
   6:   0x89be7b - rust_begin_unwind                                                                                                                                                                      
                       at libstd/panicking.rs:326                                                                                                                                                         
   7:   0x8ef047 - core::panicking::panic_fmt::h2155aa66b67fe83c                                                                                                                                          
                       at libcore/panicking.rs:77                                                                                                                                                            8:   0x8ef0b7 - core::option::expect_failed::h0ee1e896fd083f84                                                                                                                                                                at libcore/option.rs:1000                                                                                                                                                          
   9:   0x56d15f - <librespot_core::session::DispatchTask<S> as futures::future::Future>::poll::hadd618cad1963c66                                                                                           10:   0x5c87ff - <futures::future::join::Join<A, B> as futures::future::Future>::poll::hafcc638c50362462                                                                                                
  11:   0x5ed6ab - <futures::future::map::Map<A, F> as futures::future::Future>::poll::h9879fc113e6dd59c                                                                                                  
  12:   0x5791b3 - <futures::future::map_err::MapErr<A, F> as futures::future::Future>::poll::h630c333e5183bb1a                                                                                           
  13:   0x7e2e2f - futures::task_impl::std::set::hb64b5e1c0cc56bbe                                                                                                                                        
  14:   0x7e648f - tokio::executor::current_thread::CurrentRunner::set_spawn::h3b1b60459bea935d                                                                                                           
  15:   0x7eaaaf - <tokio::executor::current_thread::scheduler::Scheduler<U>>::tick::hdb9927f46af9d364                                                                                                    
  16:   0x7ec6bf - <scoped_tls::ScopedKey<T>>::set::ha4e15547481b5bf8                                                                                                                                     
  17:   0x7ebbff - <std::thread::local::LocalKey<T>>::with::had55b97dcf1a1023                                                                                                                             
  18:   0x7eb77f - <std::thread::local::LocalKey<T>>::with::h1761e86c7f8b584a                                                                                                                             
  19:   0x7ec1b7 - <std::thread::local::LocalKey<T>>::with::hbda6d445ae1bf9e8                                                                                                                             
  20:   0x7e6f4b - tokio_core::reactor::Core::poll::hbae1363e66332d87                                                                                                                                     
  21:   0x4873bb - tokio_core::reactor::Core::run::hf9c93dd339db2f7e                                                                                                                                      
  22:   0x492bff - librespot::main::h72f979f6b833cfad                                                                                                                                                     
  23:   0x46b353 - std::rt::lang_start::{{closure}}::h9cdb8adbbe2a93a7                                                                                                                                    
  24:   0x89bdf3 - std::panicking::try::do_call::he4497885895661a8                                                                                                                                        
                       at libstd/rt.rs:59                                                                                                                                                                 
                       at libstd/panicking.rs:310                                                                                                                                                         
  25:   0x8b9f5f - __rust_maybe_catch_panic                                                                                                                                                               
                       at libpanic_unwind/lib.rs:103                                                                                                                                                      
  26:   0x89ae9f - std::panic::catch_unwind::hdd9654d0e8ee1176                                                                                                                                            
                       at libstd/panicking.rs:289                                                                                                                                                         
                       at libstd/panic.rs:392                                                                                                                                                             
  27:   0x897cdb - std::rt::lang_start_internal::h4ec5eae1ccf41136                                                                                                                                        
                       at libstd/rt.rs:58                                                                                                                                                                 
  28:   0x4938a7 - main                                                                                                                                                                                   
  29: 0x76bc8677 - __libc_start_main                                                                                                                                                                      
DEBUG:librespot_core::session: drop Dispatch                                                                                                                                                              
DEBUG:librespot_connect::spirc: drop Spirc[0]                                                                                                                                                             
DEBUG:librespot_playback::player: Shutting down player thread ...                                                                                                                                         
DEBUG:librespot_playback::player: drop Player[0]                                                                                                                                                          
DEBUG:librespot_core::session: drop Session[0]                                                                                                                                                            DEBUG:librespot_core::audio_key: drop AudioKeyManager                                                                                                                                                     
DEBUG:librespot_core::channel: drop ChannelManager                                                                                                                                                        
DEBUG:librespot_core::mercury: drop MercuryManager