spotifyd icon indicating copy to clipboard operation
spotifyd copied to clipboard

Connection reset by peer (os error 104)

Open ghost opened this issue 1 year ago • 16 comments

Description Every time I start spotifyd, it plays for about an hour or two and then goes from the play state to idle. When I check journalctl, it says "subscription terminated." followed by "Connection reset by peer". After that, it starts the authentication process again. I'm not exactly sure what to do or what could be causing this.

To Reproduce

  1. Launch spotifyd with
/usr/local/bin/spotifyd --no-daemon --config-path /home/pi/.config/spotifyd/spotifyd.conf --cache-path /home/pi/.cache/spotifyd/
  1. Start playing
  2. Playstate goes from playing to idle in random intervals

Logs

Click to show logs
Oct 15 07:32:38 raspberrypi spotifyd[1024]: subscription terminated
Oct 15 07:32:38 raspberrypi spotifyd[1024]: Connection reset by peer (os error 104)
Oct 15 07:32:38 raspberrypi spotifyd[1024]: Ignoring blacklisted access point ap-gew4.                                                                                                                                                             spotify.com:4070
Oct 15 07:32:38 raspberrypi spotifyd[1024]: Ignoring blacklisted access point ap-gew4.                                                                                                                                                             spotify.com:443
Oct 15 07:32:38 raspberrypi spotifyd[1024]: Ignoring blacklisted access point ap-gew4.                                                                                                                                                             spotify.com:80
Oct 15 07:32:38 raspberrypi spotifyd[1024]: Connecting to AP "ap-gew1.spotify.com:443"
Oct 15 07:32:38 raspberrypi spotifyd[1024]: Authenticated as "xxxx" !
Oct 15 07:32:38 raspberrypi spotifyd[1024]: Mixing with softvol and volume control: Lo                                                                                                                                                             g(60.0)
Oct 15 07:32:38 raspberrypi spotifyd[1024]: Converting with ditherer: tpdf
Oct 15 07:32:38 raspberrypi spotifyd[1024]: Using AlsaSink with format: S16

Compilation flags

  • [ ] dbus_mpris
  • [ ] dbus_keyring
  • [x] alsa_backend
  • [ ] portaudio_backend
  • [ ] pulseaudio_backend
  • [ ] rodio_backend

Versions (please complete the following information):

  • OS: Raspberry Pi OS (64-bit)

ghost avatar Oct 15 '24 06:10 ghost

Isn't this #706?

alepez avatar Oct 16 '24 08:10 alepez

I have the same issue and it's a regular one. Oct 22 23:21:01 HTZ100 spotifyd[3939169]: subscription terminated Oct 22 23:21:01 HTZ100 spotifyd[3939169]: Connection reset by peer (os error 104) I can play some playlist and at some point the device is disconnected from spotify on mobile, I select the device in the list and it connect again without issue until it happen again.

I have the pulseaudio backend with Pipewire

MrZoltan avatar Oct 23 '24 07:10 MrZoltan

Isn't this #706?

I don't think it is. Not for me at least. In #706 people are talking about having to restart and VPN and/or WiFi switching maybe causing it.

I'm not using a VPN, the box running spotifyd is wired, not WiFi. My connection to spotifyd just drops (the song keeps playing - output just reverts to my phone speaker). I simply select my spotifyd server as the output device and output quickly switches back to spotifyd.

Here's my log for today with just "Loading" and "loaded" stripped out:

Oct 24 18:02:35 puck spotifyd[18745]: Ignoring blacklisted access point ap-gue1.spotify.com:4070
Oct 24 18:02:35 puck spotifyd[18745]: Ignoring blacklisted access point ap-gue1.spotify.com:443
Oct 24 18:02:35 puck spotifyd[18745]: Ignoring blacklisted access point ap-gue1.spotify.com:80
Oct 24 18:02:35 puck spotifyd[18745]: Connecting to AP "ap-gae2.spotify.com:443"
Oct 24 18:02:36 puck spotifyd[18745]: Authenticated as "__redacted__" !
Oct 24 18:02:36 puck spotifyd[18745]: Country: "AU"
Oct 24 18:02:36 puck spotifyd[18745]: Mixing with softvol and volume control: Log(60.0)
Oct 24 18:02:36 puck spotifyd[18745]: Converting with ditherer: tpdf
Oct 24 18:02:36 puck spotifyd[18745]: Using AlsaSink with format: S32
Oct 24 18:40:36 puck spotifyd[18745]: subscription terminated
Oct 24 18:40:36 puck spotifyd[18745]: Connection reset by peer (os error 104)
Oct 24 18:40:53 puck spotifyd[18745]: Ignoring blacklisted access point ap-gue1.spotify.com:4070
Oct 24 18:40:53 puck spotifyd[18745]: Ignoring blacklisted access point ap-gue1.spotify.com:443
Oct 24 18:40:53 puck spotifyd[18745]: Ignoring blacklisted access point ap-gue1.spotify.com:80
Oct 24 18:40:53 puck spotifyd[18745]: Ignoring blacklisted access point ap-gew4.spotify.com:80
Oct 24 18:40:53 puck spotifyd[18745]: Connecting to AP "ap-gae2.spotify.com:443"
Oct 24 18:40:54 puck spotifyd[18745]: Authenticated as "__redacted__" !
Oct 24 18:40:54 puck spotifyd[18745]: Country: "AU"
Oct 24 18:40:54 puck spotifyd[18745]: Mixing with softvol and volume control: Log(60.0)
Oct 24 18:40:54 puck spotifyd[18745]: Converting with ditherer: tpdf
Oct 24 18:40:54 puck spotifyd[18745]: Using AlsaSink with format: S32

It just happened once today. It's not unusual for it to happen 3-4 times in a session (a few hours).

not4smurf avatar Oct 25 '24 01:10 not4smurf

My solution is to migrate to Librespot, which has resolved this issue with a new 'keep-alive' system.

ghost avatar Nov 04 '24 07:11 ghost

My solution is to migrate to Librespot, which has resolved this issue with a new 'keep-alive' system.

Unfortunately my backend isn't supported by librespot (Pipewire) so I would love to have a fix for spotifyd

MrZoltan avatar Nov 04 '24 14:11 MrZoltan

I'm also running into this same issue. I now see that I'm using librespot as well. Same issue.

[2024-11-05T23:59:04Z ERROR librespot_core::session] Connection reset by peer (os error 104) [2024-11-05T23:59:04Z ERROR librespot_connect::spirc] subscription terminated [2024-11-05T23:59:04Z WARN librespot] Spirc shut down unexpectedly [2024-11-05T23:59:04Z WARN librespot_core::apresolve] Ignoring blacklisted access point ap-gue1.spotify.com:443 [2024-11-05T23:59:04Z INFO librespot_core::session] Connecting to AP "ap-guc3.spotify.com:4070" [2024-11-05T23:59:05Z INFO librespot_core::session] Authenticated as "redact" ! [2024-11-05T23:59:05Z INFO librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Log(60.0) [2024-11-05T23:59:05Z INFO librespot_playback::convert] Converting with ditherer: tpdf [2024-11-05T23:59:05Z INFO librespot_playback::audio_backend::pulseaudio] Using PulseAudioSink with format: S16 [2024-11-05T23:59:05Z INFO librespot_core::session] Country: "CA"

Adept9559 avatar Nov 06 '24 00:11 Adept9559

Try creating a new cache folder and run Librespot with the options --cache and --access-token. Perhaps authorizing directly with the access token will prevent the subscription from terminating.

D4vid04 avatar Nov 06 '24 09:11 D4vid04

Even though this might not be a duplicate of #706, maybe the fixes in https://github.com/Spotifyd/spotifyd/pull/1317 / https://github.com/Spotifyd/spotifyd/pull/1321 still work?

eladyn avatar Dec 30 '24 14:12 eladyn

Even though this might not be a duplicate of #706, maybe the fixes in #1317 / #1321 still work?

I had your #1317 pull request running all day without any issues. mpris seems to be faster as well. thanks for your work!!!

Exceen avatar Dec 30 '24 20:12 Exceen

I used to have random disconnects after an hour max., but yesterday I listened for multiple hours with no problems using a build of #1317. Also, previously MPRIS stopped working after connecting and disconnecting from another client a few times, that seems to be fixed as well. Huge thanks from me as well :)

mvforell avatar Jan 02 '25 10:01 mvforell

Note that the bulk part of the work on stability and everything has been done by librespot devs, so that credit goes to them. But thanks a lot for testing the branch!

eladyn avatar Jan 02 '25 13:01 eladyn

I would like to try that too but I am not familiar with the process. How do I test #1317 ? Is it in the source on "Spotifyd/spotifyd.git" or on "eladyn/spotifyd.git" ? Thanks!

MrZoltan avatar Jan 04 '25 02:01 MrZoltan

@MrZoltan You have indeed several options, but the easiest one is probably either the github CLI (gh pr checkout 1317) or git directly (git fetch origin pull/1317/head:deps_upgrade; git checkout deps_upgrade).

eladyn avatar Jan 04 '25 15:01 eladyn

@eladyn Thanks a lot for the help! It wasn't so easy but I managed to work it out in the end. It now seem that the "Connection reset by peer (os error 104)" does not appearing anymore and that is a big relief, again thanks for that. I can't help but notice that now when skipping track there is an sound artefact for a very brief moment SkipTrack->Silence->Noise->Start of next track. should I maybe write another issue with that ? It was not present before.

MrZoltan avatar Jan 07 '25 14:01 MrZoltan

Opening a new issue sounds good. If you have the time, you could also directly test this with librespot dev and if it happens over there as well, report it there.

eladyn avatar Jan 19 '25 00:01 eladyn

I just tested this via #1317, and so far things seem to be working. If anyone finds it useful, I cloned the fork mentioned in the PR and used the following Dockerfile to cross-compile for my Raspberry PI (armhf):

FROM ubuntu:18.04

# Set up cross-compiler
RUN mkdir -p /build/sysroot
RUN echo "deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports/ bionic main" | tee -a /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y -qq gcc-arm-linux-gnueabihf libc6-armhf-cross libc6-dev-armhf-cross

# Install libraries needed for build
RUN apt-get download libasound2:armhf libasound2-dev:armhf libssl-dev:armhf libssl1.1:armhf
RUN dpkg -x libasound2_*.deb /build/sysroot/
RUN dpkg -x libssl-dev*.deb /build/sysroot/
RUN dpkg -x libssl1.1*.deb /build/sysroot/
RUN dpkg -x libasound2-dev*.deb /build/sysroot/
RUN apt-get install -y -qq libasound2-dev libssl-dev libpulse-dev libdbus-1-dev

# Install Rust
RUN apt-get install -y -qq curl
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin/:${PATH}"
RUN rustup target add arm-unknown-linux-gnueabihf

# Install bindgen-cli for host system
RUN apt-get install -y -qq cmake clang-9
RUN cargo install --force --locked bindgen-cli

# Set up cross-compilation variables
ENV PKG_CONFIG_ALLOW_CROSS=1
ENV TEST=abcd
ENV RUSTFLAGS="-C linker=arm-linux-gnueabihf-gcc -L/usr/arm-linux-gnueabihf/lib -L/build/sysroot/usr/lib/arm-linux-gnueabihf -L/build/sysroot/lib/arm-linux-gnueabihf"
ENV C_INCLUDE_PATH=/build/sysroot/usr/include
ENV OPENSSL_LIB_DIR=/build/sysroot/usr/lib/arm-linux-gnueabihf
ENV OPENSSL_INCLUDE_DIR=/build/sysroot/usr/include/arm-linux-gnueabihf
ENV BINDGEN_EXTRA_CLANG_ARGS='--sysroot /usr/arm-linux-gnueabihf'

# Copy over code and perform build
COPY . .
RUN cargo build --target=arm-unknown-linux-gnueabihf --release --features '',alsa_backend 

# Once done, extract file by calling:
# sudo docker run --rm -it -v $(pwd):/host [IMAGE_ID] /bin/cp target/arm-unknown-linux-gnueabihf/release/spotifyd /host/ 

MathiasStokholm avatar Feb 10 '25 19:02 MathiasStokholm