librespot-org / librespot

Open Source Spotify client library
MIT License
4.7k stars 573 forks source link

Spotifyd crashes in alsa backend on ALSA error #1110

Closed aykevl closed 1 year ago

aykevl commented 1 year ago

Spotifyd crashes whenever I connect to it from my phone and start playing music.

To reproduce Steps to reproduce the behavior:

  1. Launch spotifyd using RUST_LOG=debug RUST_BACKTRACE=1 ./target/release/spotifyd --no-daemon
  2. Connect with any device (using the Spotify app on Android, but it probably doesn't matter)
  3. Press the play button.
  4. See the crash.

Log

Here is the log output:

Loading config from "/home/ayke/.config/spotifyd/spotifyd.conf"
No proxy specified
Using software volume controller.
Connecting to AP "ap.spotify.com:443"
Authenticated as "***" !
Country: "NL"
Using Alsa sink with format: S16
Loading <I Can't Sleep Anymore> with Spotify URI <spotify:track:3bs4FFbDtdxE4C882rIszp>
<I Can't Sleep Anymore> (214736 ms) loaded
Alsa error PCM open ALSA function 'snd_pcm_open' failed with error 'UnknownErrno: Unknown errno'
Could not start audio: Alsa error: PCM open failed
Alsa error PCM open ALSA function 'snd_pcm_open' failed with error 'UnknownErrno: Unknown errno'
Could not start audio: Alsa error: PCM open failed
The application panicked (crashed).
Message:  called `Option::unwrap()` on a `None` value
Location: /home/ayke/.cargo/registry/src/github.com-1285ae84e5963aae/librespot-playback-0.2.0/src/audio_backend/alsa.rs:160

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 10 frames hidden ⋮                              
  11: core::panicking::panic::h1a22c9da332d8153
      at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/core/src/panicking.rs:115
  12: <librespot_playback::audio_backend::alsa::AlsaSink as librespot_playback::audio_backend::SinkAsBytes>::write_bytes::h2d34d191583d345e
      at <unknown source file>:<unknown line>
  13: <librespot_playback::audio_backend::alsa::AlsaSink as librespot_playback::audio_backend::Sink>::write::h939760c231527758
      at <unknown source file>:<unknown line>
  14: <librespot_playback::player::PlayerInternal as core::future::future::Future>::poll::h049818c5a7e06791
      at <unknown source file>:<unknown line>
  15: futures_executor::local_pool::block_on::hd965bf91a7a89bdb
      at <unknown source file>:<unknown line>
  16: std::sys_common::backtrace::__rust_begin_short_backtrace::h6490d750edd07118
      at <unknown source file>:<unknown line>
  17: core::ops::function::FnOnce::call_once{{vtable.shim}}::h686ea76fbed56867
      at <unknown source file>:<unknown line>
  18: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h81794a412fc9f85c
      at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/alloc/src/boxed.rs:1987
  19: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h262fe31b4a749244
      at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/alloc/src/boxed.rs:1987
  20: std::sys::unix::thread::Thread::new::thread_start::hf1c52a992ed5a078
      at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/sys/unix/thread.rs:108

Most likely the crash is related to Alsa error PCM open ALSA function 'snd_pcm_open' failed with error 'UnknownErrno: Unknown errno' but even then, IMHO it shouldn't crash.

Host (what you are running librespot on):

Additional context

There is definitely an alsa problem here though, so the fact that it doesn't start to play is not a bug. But I don't think it should crash.

$ aplay /usr/share/sounds/alsa/Front_Center.wav
aplay: main:830: audio open error: Unknown error 524

EDIT: the actual error was that alsa had rearranged sound cards and it was trying to output on the HDMI port (with no connected display or anything).

roderickvd commented 1 year ago

Spotifyd is a separate project that, last time I looked, depends on an old version of librespot. Newer versions have much improved error handling.