librespot-org / librespot

Open Source Spotify client library
MIT License
4.84k stars 610 forks source link

Zeroconf fails with "Setting up dns-sd failed: Address already in use (os error 98)" #1111

Closed khink closed 1 year ago

khink commented 1 year ago

Describe the bug

raspotify keeps crashing with the message "Setting up dns-sd failed: Address already in use (os error 98)".

I filed this in raspotify first, but the error is from librespot, so i thought it made sense to ask/report here.

To reproduce

1.tail -f /var/log/syslog

  1. Launch sudo systemctl start raspotify
  2. In the log, see "Setting up dns-sd failed: Address already in use (os error 98)", and next "Discovery is unavailable and no credentials provided. Authentication is not possible."

Log

pi@raspberrypi:~ $ journalctl
...
Jan 25 22:01:11 raspberrypi librespot[8216]: [2023-01-25T21:01:11Z WARN  librespot] Without a `--cache` / `-c` path, and/or if the `--disable-audio-cache` / `-G` flag is set, `--cache-size-limit` / `-M` has no >
Jan 25 22:01:11 raspberrypi librespot[8216]: [2023-01-25T21:01:11Z WARN  librespot] Could not initialise discovery: Setting up dns-sd failed: Address already in use (os error 98)
Jan 25 22:01:11 raspberrypi librespot[8216]: [2023-01-25T21:01:11Z ERROR librespot] Discovery is unavailable and no credentials provided. Authentication is not possible.
Jan 25 22:01:11 raspberrypi systemd[1]: raspotify.service: Main process exited, code=exited, status=1/FAILURE
Jan 25 22:01:11 raspberrypi systemd[1]: raspotify.service: Failed with result 'exit-code'.
Jan 25 22:01:11 raspberrypi systemd[1]: raspotify.service: Triggering OnFailure= dependencies.
Jan 25 22:01:11 raspberrypi systemd[1]: Starting Raspotify Crash Report Generator...
Jan 25 22:01:12 raspberrypi systemd[1]: raspotify-crash-report-generator.service: Succeeded.
Jan 25 22:01:12 raspberrypi systemd[1]: Finished Raspotify Crash Report Generator.
Jan 25 22:01:12 raspberrypi systemd[1]: raspotify-crash-report-generator.service: Consumed 1.509s CPU time.

Host (what you are running librespot on):

I'm running a standard raspotify on bullseye on a Pi 3. It's running without a monitor (only SSH access), although lxde is installed (i think from when i first set it up a year or two ago).

pi@raspberrypi:~ $ sudo apt show raspotify
Package: raspotify
Version: 0.43.26~librespot.v0.4.2-a56a567
...

pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
...

pi@raspberrypi:~ $ cat /proc/cpuinfo
processor   : 0
model name  : ARMv7 Processor rev 4 (v7l)
...
Hardware    : BCM2835
Revision    : a02082
Serial      : 00000000e6a3a0de
Model       : Raspberry Pi 3 Model B Rev 1.2

Additional context

kingosticks commented 1 year ago

This looks like a system-level issue, not a librespot bug. The Raspotify project should be able to help you.

kingosticks commented 1 year ago

Fundamentally the issue is that the librespot binary packaged in Raspotify provides its own Zeroconf server. Your system seems to also have a standalone Zeroconf server running (e.g. Avahi). It probably got installed by another package during your recent system updates. When librespot tries to start its integrated zeroconf server, it finds the port is already taken by Avahi. A solution is to remove Avahi. That might break something else on your system which is using Avahi. An alternate solution is the config change you already did. There is no librespot bug here.

There's some info at https://github.com/dtcooper/raspotify/search?q=with-dns-sd&type=issues

khink commented 1 year ago

Thanks for taking the time to reply!

Indeed i have avahi.

pi@raspberrypi:~ $ apt list avahi-daemon 
Listing... Done
avahi-daemon/stable,now 0.8-5+deb11u1 armhf [installed]

But disabling it doesn't help:

pi@raspberrypi:~ $ sudo service avahi-daemon stop
Warning: Stopping avahi-daemon.service, but it can still be activated by:
  avahi-daemon.socket
pi@raspberrypi:~ $ sudo vi /etc/raspotify/conf # comment out LIBRESPOT_DISABLE_DISCOVERY=
pi@raspberrypi:~ $ sudo systemctl restart raspotify
pi@raspberrypi:~ $ tail -f /var/log/syslog
...
Jan 26 14:27:10 raspberrypi librespot[23953]: [2023-01-26T13:27:10Z WARN  librespot] Could not initialise discovery: Setting up dns-sd failed: Address already in use (os error 98)
...

Even when i completely remove it:

pi@raspberrypi:~ $ sudo apt remove avahi-daemon 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  bind9-host bind9-libs libavahi-core7 libdaemon0 libfstrm0 libmaxminddb0 libprotobuf-c1 libuv1
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  avahi-daemon ipp-usb libnss-mdns
0 upgraded, 0 newly installed, 3 to remove and 1 not upgraded.
After this operation, 5,160 kB disk space will be freed.
Do you want to continue? [Y/n] Y

After restart:

Jan 26 14:32:00 raspberrypi librespot[24421]: [2023-01-26T13:32:00Z WARN  librespot] Could not initialise discovery: Setting up dns-sd failed: Address already in use (os error 98)

So are we sure another zeroconf server is running, and if yes how do we find out which one it is? (Also, not sure how the issue search you refer to relates to this though, as none of them is about this "Address already in use" error.)

Update edit: After a reboot, the problem has gone. :100: for your avahi suggestion. Thanks!