librespot-org / librespot

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

Unable to run as root or as service #1095

Closed jcv8-dev closed 1 year ago

jcv8-dev commented 1 year ago

Describe the bug Librespot immediately crashes when run with root privileges Librespot immediately crashes when run from root user with runuser -l user -c 'librespot -n Librespot' where user is able to run the same command.

The same error appears when I run Librespot as a service with my librespot.service: `[Unit] Description=librespot Requires=network-online.target After=network-online.target

[Service] Type=simple User=jcvb Group=audio Restart=always

RestartSec=10

Environment="RUST_BACKTRACE=full" ExecStart=/usr/local/bin/librespot.dir/librespot --name "LIBRESPOT" -b 320 -c /tmp --enable-volume-normalisation --initial-volume 30 --device-type speaker

[Install] WantedBy=multi-user.target `

To reproduce Steps to reproduce the behavior:

  1. sudo runuser -l user -c 'librespot -n Librespot' or sudo librespot -n Librespot
  2. watch librespot crash

Log root@jcvbserv:/home/jcvb/librespot/target/debug# runuser -l jcvb -c ' librespot --name "LIBRE" -b 320 -c /tmp --enable-volume-normalisation --initia l-volume 30 --device-type speaker --verbose' [2023-01-09T07:59:02Z INFO librespot] librespot 0.4.2 UNKNOWN (Built on 2023-01-06, Build ID: V28ESijR, Profile: release) [2023-01-09T07:59:02Z TRACE librespot] Command line argument(s): [2023-01-09T07:59:02Z TRACE librespot] name "LIBRE" [2023-01-09T07:59:02Z TRACE librespot] b "320" [2023-01-09T07:59:02Z TRACE librespot] c "/tmp" [2023-01-09T07:59:02Z TRACE librespot] enable-volume-normalisation [2023-01-09T07:59:02Z TRACE librespot] initial-volume "30" [2023-01-09T07:59:02Z TRACE librespot] device-type "speaker" [2023-01-09T07:59:02Z TRACE librespot] verbose [2023-01-09T07:59:02Z TRACE librespot] Using cached credentials. [2023-01-09T07:59:02Z DEBUG librespot_discovery::server] Zeroconf server listening on 0.0.0.0:43655 [2023-01-09T07:59:02Z WARN librespot_core::apresolve] Ignoring blacklisted access point ap-gew4.spotify.com:4070 [2023-01-09T07:59:02Z WARN librespot_core::apresolve] Ignoring blacklisted access point ap-gew4.spotify.com:443 [2023-01-09T07:59:02Z WARN librespot_core::apresolve] Ignoring blacklisted access point ap-gew4.spotify.com:80 [2023-01-09T07:59:02Z WARN librespot_core::apresolve] Ignoring blacklisted access point ap-gue1.spotify.com:80 [2023-01-09T07:59:02Z INFO librespot_core::session] Connecting to AP "ap-gae2.spotify.com:4070" [2023-01-09T07:59:03Z INFO librespot_core::session] Authenticated as "mnnfux" ! [2023-01-09T07:59:03Z DEBUG librespot_core::session] new Session[0] [2023-01-09T07:59:03Z INFO librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Log(60.0) [2023-01-09T07:59:03Z DEBUG librespot_playback::player] Normalisation Type: Auto [2023-01-09T07:59:03Z DEBUG librespot_playback::player] Normalisation Pregain: 0.0 dB [2023-01-09T07:59:03Z DEBUG librespot_playback::player] Normalisation Threshold: -2.0 dBFS [2023-01-09T07:59:03Z DEBUG librespot_playback::player] Normalisation Method: Dynamic [2023-01-09T07:59:03Z DEBUG librespot_playback::player] Normalisation Attack: 5 ms [2023-01-09T07:59:03Z DEBUG librespot_playback::player] Normalisation Release: 100 ms [2023-01-09T07:59:03Z DEBUG librespot_playback::player] Normalisation Knee: 5 dB [2023-01-09T07:59:03Z DEBUG librespot_connect::spirc] new Spirc[0] [2023-01-09T07:59:03Z DEBUG librespot_connect::spirc] canonical_username: mnnfux [2023-01-09T07:59:03Z DEBUG librespot::component] new MercuryManager [2023-01-09T07:59:03Z DEBUG librespot_playback::player] new Player[0] [2023-01-09T07:59:03Z INFO librespot_playback::convert] Converting with ditherer: tpdf [2023-01-09T07:59:03Z DEBUG librespot_playback::mixer::mappings] Input volume 19660 mapped to: 0.79% [2023-01-09T07:59:03Z INFO librespot_playback::audio_backend::rodio] Using Rodio sink with format S16 and cpal host: ALSA [2023-01-09T07:59:03Z INFO librespot_playback::audio_backend::rodio] Using audio device: default [2023-01-09T07:59:03Z DEBUG librespot_core::session] Session[0] strong=3 weak=2 [2023-01-09T07:59:03Z INFO librespot_core::session] Country: "DE" thread '<unnamed>' panicked at 'calledResult::unwrap()on anErrvalue: StreamError(BuildStreamError(BackendSpecific { err: BackendSpecificError { description: "ALSA function 'snd_pcm_sw_params' failed with error 'EINVAL: Invalid argument'" } }))', playback/src/audio_backend/rodio.rs:178:53 stack backtrace: 0: 0x55bd7d52930c - std::backtrace_rs::backtrace::libunwind::trace::h76d34c316a8bb75b at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x55bd7d52930c - std::backtrace_rs::backtrace::trace_unsynchronized::hb782d75313085067 at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x55bd7d52930c - std::sys_common::backtrace::_print_fmt::hee022c31c5bcfcc1 at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/sys_common/backtrace.rs:66:5 3: 0x55bd7d52930c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h054c846eb7f0e1fb at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/sys_common/backtrace.rs:45:22 4: 0x55bd7d54f5de - core::fmt::write::hcef9c23bf27d039c at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/core/src/fmt/mod.rs:1194:17 5: 0x55bd7d510701 - std::io::Write::write_fmt::h6f6e0727690d342c at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/io/mod.rs:1655:15 6: 0x55bd7d5137a5 - std::sys_common::backtrace::_print::h591ece144505a7d5 at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/sys_common/backtrace.rs:48:5 7: 0x55bd7d5137a5 - std::sys_common::backtrace::print::hbdcd241dc6539260 at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/sys_common/backtrace.rs:35:9 8: 0x55bd7d5137a5 - std::panicking::default_hook::{{closure}}::hc934c90a9f702809 at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/panicking.rs:295:22 9: 0x55bd7d513459 - std::panicking::default_hook::h984be39605172602 at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/panicking.rs:314:9 10: 0x55bd7d513def - std::panicking::rust_panic_with_hook::h04be8cf992436914 at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/panicking.rs:698:17 11: 0x55bd7d529647 - std::panicking::begin_panic_handler::{{closure}}::h47ebda0479239463 at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/panicking.rs:588:13 12: 0x55bd7d529424 - std::sys_common::backtrace::__rust_end_short_backtrace::h1690aafc8ab8529a at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/sys_common/backtrace.rs:138:18 13: 0x55bd7d513902 - rust_begin_unwind at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/panicking.rs:584:5 14: 0x55bd7d0b1bf3 - core::panicking::panic_fmt::h8531284c14f462dc at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/core/src/panicking.rs:143:14 15: 0x55bd7d0b1cd3 - core::result::unwrap_failed::h6972a430d3981bcd at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/core/src/result.rs:1785:5 16: 0x55bd7d22e173 - librespot_playback::audio_backend::rodio::mk_rodio::he7b6cc319e3c72fa 17: 0x55bd7d1606ff - std::sys_common::backtrace::__rust_begin_short_backtrace::h5b0cd29876ed4399 18: 0x55bd7d13baa4 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h806a608dcba61274 19: 0x55bd7d51cec3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h77928282605e7a97 at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/alloc/src/boxed.rs:1861:9 20: 0x55bd7d51cec3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hbed4863049f4a2cf at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/alloc/src/boxed.rs:1861:9 21: 0x55bd7d51cec3 - std::sys::unix::thread::Thread::new::thread_start::h205b04056d2da3d7 at /build/rustc-ZOqcvC/rustc-1.61.0+dfsg1/library/std/src/sys/unix/thread.rs:108:17 22: 0x7fe5589a5b43 - <unknown> 23: 0x7fe558a37a00 - <unknown> 24: 0x0 - <unknown> [2023-01-09T07:59:03Z DEBUG librespot_core::mercury] subscribed uri=hm://remote/user/mnnfux/ count=0 [2023-01-09T07:59:04Z DEBUG librespot_connect::spirc] kMessageTypeNotify "JCVB" 573c2e647f019ef586ed0e7615c3b497607236e4 361382617 1673251143630 kPla yStatusStop [2023-01-09T07:59:04Z DEBUG librespot_connect::spirc] kMessageTypeNotify "OnePlus Nord CE 5G" b2e87f52d302a801ce24aa90d7dc60a213ffe337 361382617 1673 251143630 kPlayStatusPlay [2023-01-09T07:59:49Z DEBUG librespot_connect::spirc] kMessageTypeNotify "OnePlus Nord CE 5G" b2e87f52d302a801ce24aa90d7dc60a213ffe337 361427942 1673251188955 kPlayStatusPlay

Host (what you are running librespot on):

Additional context Please note that the same command runs fine and plays audio when run logged in as "jcvb" user. In case this is not a problem with librespot, but with my audio config I would appreciate being pointed in the right direction so I can fix this.

jcv8-dev commented 1 year ago

Fixed it. I needed to run pulseaudio -D as root on startup.