[GH-ISSUE #417] Librespot crashes upon connection #269

Closed
opened 2026-02-27 19:29:44 +03:00 by kerem · 2 comments
Owner

Originally created by @mordax7 on GitHub (Dec 28, 2019).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/417

There is sometimes a problem that is really hard to fix. Basically how to reproduce it is like follows:

(use two Spotify accounts).

  • Connect and play a song from account 1.
  • Play song locally on account 2 device.
  • Try connecting(taking over) Librespot connect
  • This is when Librespot will crash and not recover by itself

At this point, the only way to recover is by stopping Librespot and the Spotify client on your device. Once both stopped you need to first open your Spotify client and afterwards start Librespot, then you will be able to connect to Librespot connect.

Here the logs:

[30506]: [2019-12-28T22:50:56Z INFO  librespot] librespot (raspotify v0.13.1-1-ga7274ae) b634117 (2019-12-17). Built on 2019-12-27. Build ID: lqPey9SF
[30506]: [2019-12-28T22:51:00Z INFO  librespot_core::session] Connecting to AP "gew1-accesspoint-a-fn6q.ap.spotify.com:4070"
[30506]: [2019-12-28T22:51:00Z INFO  librespot_core::session] Authenticated as "pyl3v4faqqytciloorhidn4px" !
[30506]: [2019-12-28T22:51:00Z INFO  librespot_playback::audio_backend::alsa] Using alsa sink
[30506]: [2019-12-28T22:51:00Z INFO  librespot_core::session] Country: "DE"
[30506]: [2019-12-28T22:51:01Z INFO  librespot_playback::player] Loading <I Dream Of You> with Spotify URI <spotify:track:2hk0vxMqUzHmediqECGXlh>
[30506]: [2019-12-28T22:51:01Z INFO  librespot_playback::player] <I Dream Of You> loaded
[30506]: thread 'main' panicked at 'channel closed', src/libcore/option.rs:1185:5
[30506]: stack backtrace:
[30506]:    0:   0x965628 - backtrace::backtrace::libunwind::trace::h65597d255cb1398b
[30506]:                        at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
[30506]:    1:   0x965628 - backtrace::backtrace::trace_unsynchronized::h85fd8d34e214d876
[30506]:                        at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
[30506]:    2:   0x965628 - std::sys_common::backtrace::_print_fmt::he35a37f9b8e4b952
[30506]:                        at src/libstd/sys_common/backtrace.rs:77
[30506]:    3:   0x965628 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he0e762d8ed66f8bc
[30506]:                        at src/libstd/sys_common/backtrace.rs:61
[30506]:    4:   0x988290 - core::fmt::write::h1f444f4312eb6c27
[30506]:                        at src/libcore/fmt/mod.rs:1028
[30506]:    5:   0x960298 - std::io::Write::write_fmt::hfae316bf0dea24b4
[30506]:                        at src/libstd/io/mod.rs:1412
[30506]:    6:   0x967bd8 - std::sys_common::backtrace::_print::ha081546d159043e6
[30506]:                        at src/libstd/sys_common/backtrace.rs:65
[30506]:    7:   0x967bd8 - std::sys_common::backtrace::print::h5ae28d5a72f95be5
[30506]:                        at src/libstd/sys_common/backtrace.rs:50
[30506]:    8:   0x967bd8 - std::panicking::default_hook::{{closure}}::h00506bfaacab8ec5
[30506]:                        at src/libstd/panicking.rs:188
[30506]:    9:   0x967838 - std::panicking::default_hook::h55fa199021de9a28
[30506]:                        at src/libstd/panicking.rs:205
[30506]:   10:   0x9682d4 - std::panicking::rust_panic_with_hook::h61149c5bf815a5b0
[30506]:                        at src/libstd/panicking.rs:464
[30506]:   11:   0x967ed8 - std::panicking::continue_panic_fmt::h8c2cbca8aac85ef4
[30506]:                        at src/libstd/panicking.rs:373
[30506]:   12:   0x967dd0 - rust_begin_unwind
[30506]:                        at src/libstd/panicking.rs:302
[30506]:   13:   0x984050 - core::panicking::panic_fmt::hdeb7979ab6591473
[30506]:                        at src/libcore/panicking.rs:139
[30506]:   14:   0x9840b8 - core::option::expect_failed::h6c3ec3658ee2670d
[30506]:                        at src/libcore/option.rs:1185
[30506]:   15:   0x60974c - librespot_core::channel::Channel::recv_packet::he77700390f5949c6
[30506]:   16:   0x609948 - <librespot_core::channel::Channel as futures::stream::Stream>::poll::h186ea39dab8a047d
[30506]:   17:   0x60a0b0 - <librespot_core::channel::ChannelData as futures::stream::Stream>::poll::h8634377478141f72
[30506]:   18:   0x5942d4 - <librespot_audio::fetch::AudioFileFetchDataReceiver as futures::future::Future>::poll::h2641010589e6c99f
[30506]:   19:   0x8ed254 - futures::task_impl::std::set::h63cf6496d0f0b529
[30506]:   20:   0x8e3aa4 - tokio_current_thread::CurrentRunner::set_spawn::h61a5b2343957ad1c
[30506]:   21:   0x8f5c60 - tokio_current_thread::scheduler::Scheduler<U>::tick::hc123f3341884045a
[30506]:   22:   0x8e3c20 - tokio_current_thread::Entered<P>::turn::hc37f2a4df2f72285
[30506]:   23:   0x8e8a80 - scoped_tls::ScopedKey<T>::set::h2e298a643239aee5
[30506]:   24:   0x8f4f54 - std::thread::local::LocalKey<T>::with::hc192f4e7c2710385
[30506]:   25:   0x8f548c - std::thread::local::LocalKey<T>::with::hd2335362d7a3ac57
[30506]:   26:   0x8f4b9c - std::thread::local::LocalKey<T>::with::h517e890b536e3b0d
[30506]:   27:   0x8f2468 - tokio_core::reactor::Core::poll::h1e5023ce8107152a
[30506]:   28:   0x4af6f8 - tokio_core::reactor::Core::run::h5bf2ec6a73920ff8
[30506]:   29:   0x4bb978 - librespot::main::h0e1eea195edfb866
[30506]:   30:   0x490a7c - std::rt::lang_start::{{closure}}::he248ace8ff883d90
[30506]:   31:   0x967d48 - std::rt::lang_start_internal::{{closure}}::h573944590855ff7b
[30506]:                        at src/libstd/rt.rs:48
[30506]:   32:   0x967d48 - std::panicking::try::do_call::hf1a1bb85fb9db97b
[30506]:                        at src/libstd/panicking.rs:287
[30506]:   33:   0x96f440 - __rust_maybe_catch_panic
[30506]:                        at src/libpanic_unwind/lib.rs:78
[30506]:   34:   0x968760 - std::panicking::try::h75da29acad739f50
[30506]:                        at src/libstd/panicking.rs:265
[30506]:   35:   0x968760 - std::panic::catch_unwind::haf0421e667687a32
[30506]:                        at src/libstd/panic.rs:396
[30506]:   36:   0x968760 - std::rt::lang_start_internal::h382bfca60988e23d
[30506]:                        at src/libstd/rt.rs:47
[30506]:   37:   0x4bc8cc - main
[30506]:   38: 0x76ccb718 - __libc_start_main
[1]: raspotify.service: Main process exited, code=exited, status=101/n/a
[1]: raspotify.service: Failed with result 'exit-code'.
[1]: raspotify.service: Service RestartSec=10s expired, scheduling restart.
[1]: raspotify.service: Scheduled restart job, restart counter is at 1.
[1]: Stopped Raspotify.
[1]: Starting Raspotify...
[1]: Started Raspotify.
[30530]: [2019-12-28T22:51:19Z INFO  librespot] librespot (raspotify v0.13.1-1-ga7274ae) b634117 (2019-12-17). Built on 2019-12-27. Build ID: lqPey9SF
Originally created by @mordax7 on GitHub (Dec 28, 2019). Original GitHub issue: https://github.com/librespot-org/librespot/issues/417 There is sometimes a problem that is really hard to fix. Basically how to reproduce it is like follows: (use two Spotify accounts). * Connect and play a song from account 1. * Play song locally on account 2 device. * Try connecting(taking over) Librespot connect * This is when Librespot will crash and not recover by itself At this point, the only way to recover is by stopping Librespot and the Spotify client on your device. Once both stopped you need to first open your Spotify client and afterwards start Librespot, then you will be able to connect to Librespot connect. Here the logs: ``` [30506]: [2019-12-28T22:50:56Z INFO librespot] librespot (raspotify v0.13.1-1-ga7274ae) b634117 (2019-12-17). Built on 2019-12-27. Build ID: lqPey9SF [30506]: [2019-12-28T22:51:00Z INFO librespot_core::session] Connecting to AP "gew1-accesspoint-a-fn6q.ap.spotify.com:4070" [30506]: [2019-12-28T22:51:00Z INFO librespot_core::session] Authenticated as "pyl3v4faqqytciloorhidn4px" ! [30506]: [2019-12-28T22:51:00Z INFO librespot_playback::audio_backend::alsa] Using alsa sink [30506]: [2019-12-28T22:51:00Z INFO librespot_core::session] Country: "DE" [30506]: [2019-12-28T22:51:01Z INFO librespot_playback::player] Loading <I Dream Of You> with Spotify URI <spotify:track:2hk0vxMqUzHmediqECGXlh> [30506]: [2019-12-28T22:51:01Z INFO librespot_playback::player] <I Dream Of You> loaded [30506]: thread 'main' panicked at 'channel closed', src/libcore/option.rs:1185:5 [30506]: stack backtrace: [30506]: 0: 0x965628 - backtrace::backtrace::libunwind::trace::h65597d255cb1398b [30506]: at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88 [30506]: 1: 0x965628 - backtrace::backtrace::trace_unsynchronized::h85fd8d34e214d876 [30506]: at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66 [30506]: 2: 0x965628 - std::sys_common::backtrace::_print_fmt::he35a37f9b8e4b952 [30506]: at src/libstd/sys_common/backtrace.rs:77 [30506]: 3: 0x965628 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he0e762d8ed66f8bc [30506]: at src/libstd/sys_common/backtrace.rs:61 [30506]: 4: 0x988290 - core::fmt::write::h1f444f4312eb6c27 [30506]: at src/libcore/fmt/mod.rs:1028 [30506]: 5: 0x960298 - std::io::Write::write_fmt::hfae316bf0dea24b4 [30506]: at src/libstd/io/mod.rs:1412 [30506]: 6: 0x967bd8 - std::sys_common::backtrace::_print::ha081546d159043e6 [30506]: at src/libstd/sys_common/backtrace.rs:65 [30506]: 7: 0x967bd8 - std::sys_common::backtrace::print::h5ae28d5a72f95be5 [30506]: at src/libstd/sys_common/backtrace.rs:50 [30506]: 8: 0x967bd8 - std::panicking::default_hook::{{closure}}::h00506bfaacab8ec5 [30506]: at src/libstd/panicking.rs:188 [30506]: 9: 0x967838 - std::panicking::default_hook::h55fa199021de9a28 [30506]: at src/libstd/panicking.rs:205 [30506]: 10: 0x9682d4 - std::panicking::rust_panic_with_hook::h61149c5bf815a5b0 [30506]: at src/libstd/panicking.rs:464 [30506]: 11: 0x967ed8 - std::panicking::continue_panic_fmt::h8c2cbca8aac85ef4 [30506]: at src/libstd/panicking.rs:373 [30506]: 12: 0x967dd0 - rust_begin_unwind [30506]: at src/libstd/panicking.rs:302 [30506]: 13: 0x984050 - core::panicking::panic_fmt::hdeb7979ab6591473 [30506]: at src/libcore/panicking.rs:139 [30506]: 14: 0x9840b8 - core::option::expect_failed::h6c3ec3658ee2670d [30506]: at src/libcore/option.rs:1185 [30506]: 15: 0x60974c - librespot_core::channel::Channel::recv_packet::he77700390f5949c6 [30506]: 16: 0x609948 - <librespot_core::channel::Channel as futures::stream::Stream>::poll::h186ea39dab8a047d [30506]: 17: 0x60a0b0 - <librespot_core::channel::ChannelData as futures::stream::Stream>::poll::h8634377478141f72 [30506]: 18: 0x5942d4 - <librespot_audio::fetch::AudioFileFetchDataReceiver as futures::future::Future>::poll::h2641010589e6c99f [30506]: 19: 0x8ed254 - futures::task_impl::std::set::h63cf6496d0f0b529 [30506]: 20: 0x8e3aa4 - tokio_current_thread::CurrentRunner::set_spawn::h61a5b2343957ad1c [30506]: 21: 0x8f5c60 - tokio_current_thread::scheduler::Scheduler<U>::tick::hc123f3341884045a [30506]: 22: 0x8e3c20 - tokio_current_thread::Entered<P>::turn::hc37f2a4df2f72285 [30506]: 23: 0x8e8a80 - scoped_tls::ScopedKey<T>::set::h2e298a643239aee5 [30506]: 24: 0x8f4f54 - std::thread::local::LocalKey<T>::with::hc192f4e7c2710385 [30506]: 25: 0x8f548c - std::thread::local::LocalKey<T>::with::hd2335362d7a3ac57 [30506]: 26: 0x8f4b9c - std::thread::local::LocalKey<T>::with::h517e890b536e3b0d [30506]: 27: 0x8f2468 - tokio_core::reactor::Core::poll::h1e5023ce8107152a [30506]: 28: 0x4af6f8 - tokio_core::reactor::Core::run::h5bf2ec6a73920ff8 [30506]: 29: 0x4bb978 - librespot::main::h0e1eea195edfb866 [30506]: 30: 0x490a7c - std::rt::lang_start::{{closure}}::he248ace8ff883d90 [30506]: 31: 0x967d48 - std::rt::lang_start_internal::{{closure}}::h573944590855ff7b [30506]: at src/libstd/rt.rs:48 [30506]: 32: 0x967d48 - std::panicking::try::do_call::hf1a1bb85fb9db97b [30506]: at src/libstd/panicking.rs:287 [30506]: 33: 0x96f440 - __rust_maybe_catch_panic [30506]: at src/libpanic_unwind/lib.rs:78 [30506]: 34: 0x968760 - std::panicking::try::h75da29acad739f50 [30506]: at src/libstd/panicking.rs:265 [30506]: 35: 0x968760 - std::panic::catch_unwind::haf0421e667687a32 [30506]: at src/libstd/panic.rs:396 [30506]: 36: 0x968760 - std::rt::lang_start_internal::h382bfca60988e23d [30506]: at src/libstd/rt.rs:47 [30506]: 37: 0x4bc8cc - main [30506]: 38: 0x76ccb718 - __libc_start_main [1]: raspotify.service: Main process exited, code=exited, status=101/n/a [1]: raspotify.service: Failed with result 'exit-code'. [1]: raspotify.service: Service RestartSec=10s expired, scheduling restart. [1]: raspotify.service: Scheduled restart job, restart counter is at 1. [1]: Stopped Raspotify. [1]: Starting Raspotify... [1]: Started Raspotify. [30530]: [2019-12-28T22:51:19Z INFO librespot] librespot (raspotify v0.13.1-1-ga7274ae) b634117 (2019-12-17). Built on 2019-12-27. Build ID: lqPey9SF ```
kerem closed this issue 2026-02-27 19:29:45 +03:00
Author
Owner

@kaymes commented on GitHub (Jan 22, 2020):

Looking at the error message and the code, the issue seems to be missing error handling when the connection is shut down.

in channel.rs:

impl Channel {
    fn recv_packet(&mut self) -> Poll<Bytes, ChannelError> {
        let (cmd, packet) = match self.receiver.poll() {
            Ok(Async::Ready(t)) => t.expect("channel closed"),
            Ok(Async::NotReady) => return Ok(Async::NotReady),
            Err(()) => unreachable!(),
        };

        if cmd == 0xa {
            let code = BigEndian::read_u16(&packet.as_ref()[..2]);
            error!("channel error: {} {}", packet.len(), code);

            self.state = ChannelState::Closed;

            Err(ChannelError)
        } else {
            Ok(Async::Ready(packet))
        }
    }

The t.expect("channel closed") causes the panic you see. Instead of using expect the error should be caught and a ChannelError should be issued.

When a new account takes over, practically everything is shut down and new server connections are made. If this happens while data is being downloaded some of the data-receiving futures may still be active. Thus, the error of shut-down network sessions must be handled correctly.

<!-- gh-comment-id:576991723 --> @kaymes commented on GitHub (Jan 22, 2020): Looking at the error message and the code, the issue seems to be missing error handling when the connection is shut down. in channel.rs: ``` impl Channel { fn recv_packet(&mut self) -> Poll<Bytes, ChannelError> { let (cmd, packet) = match self.receiver.poll() { Ok(Async::Ready(t)) => t.expect("channel closed"), Ok(Async::NotReady) => return Ok(Async::NotReady), Err(()) => unreachable!(), }; if cmd == 0xa { let code = BigEndian::read_u16(&packet.as_ref()[..2]); error!("channel error: {} {}", packet.len(), code); self.state = ChannelState::Closed; Err(ChannelError) } else { Ok(Async::Ready(packet)) } } ``` The `t.expect("channel closed")` causes the panic you see. Instead of using `expect` the error should be caught and a ChannelError should be issued. When a new account takes over, practically everything is shut down and new server connections are made. If this happens while data is being downloaded some of the data-receiving futures may still be active. Thus, the error of shut-down network sessions must be handled correctly.
Author
Owner

@kaymes commented on GitHub (Jan 22, 2020):

I created PR #425 to fix the issue but I can't test it myself at the moment.
@xMordax could you please test whether the issue is gone with the new code and if not post the error messages again.

<!-- gh-comment-id:577023666 --> @kaymes commented on GitHub (Jan 22, 2020): I created PR #425 to fix the issue but I can't test it myself at the moment. @xMordax could you please test whether the issue is gone with the new code and if not post the error messages again.
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#269
No description provided.