[GH-ISSUE #1133] Undiscoverable when launched at the same time as avahi-daemon #531

Closed
opened 2026-02-27 19:31:08 +03:00 by kerem · 9 comments
Owner

Originally created by @ettom on GitHub (Mar 19, 2023).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/1133

Describe the bug
Librespot (with dns-sd backend) stays in an undiscoverable state if launched closely together with avahi-daemon.

To reproduce
Steps to reproduce the behavior:

  1. systemctl stop avahi-daemon
  2. Launch librespot with:
while :; do librespot --zeroconf-port=5354 --volume-ctrl=linear --name Snapcast --bitrate 320 --backend pipe --initial-volume 100 --verbose; sleep 0.5; done

Librespot fails to start until avahi is started:

[2023-03-19T21:02:13Z WARN  librespot] Could not initialise discovery: Setting up dns-sd failed: DNS-SD Error: Unknown.
[2023-03-19T21:02:13Z ERROR librespot] Discovery is unavailable and no credentials provided. Authentication is not possible.
  1. systemctl start avahi-daemon

Librespot now starts, but the instance is not discoverable until librespot is launched again. Some kind of a race condition? Additionally, restarting avahi-daemon while librespot is running (in a discoverable state) will make it undiscoverable until restarted.

Log:

[2023-03-19T20:57:14Z INFO  librespot] librespot 0.4.2 UNKNOWN (Built on 2023-03-14, Build ID: 315532800, Profile: release)
[2023-03-19T20:57:14Z TRACE librespot] Command line argument(s):
[2023-03-19T20:57:14Z TRACE librespot] 		zeroconf-port "5354"
[2023-03-19T20:57:14Z TRACE librespot] 		volume-ctrl "linear"
[2023-03-19T20:57:14Z TRACE librespot] 		name "Snapcast"
[2023-03-19T20:57:14Z TRACE librespot] 		bitrate "320"
[2023-03-19T20:57:14Z TRACE librespot] 		backend "pipe"
[2023-03-19T20:57:14Z TRACE librespot] 		initial-volume "100"
[2023-03-19T20:57:14Z TRACE librespot] 		verbose
[2023-03-19T20:57:14Z DEBUG librespot_discovery::server] Zeroconf server listening on 0.0.0.0:5354
*** WARNING *** The program 'librespot' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/blog/projects/avahi-compat.html>

Host (what you are running librespot on):

  • OS: NixOS 22.11
  • Platform: x86
# avahi-daemon --version
avahi-daemon 0.8
Originally created by @ettom on GitHub (Mar 19, 2023). Original GitHub issue: https://github.com/librespot-org/librespot/issues/1133 **Describe the bug** Librespot (with dns-sd backend) stays in an undiscoverable state if launched closely together with avahi-daemon. **To reproduce** Steps to reproduce the behavior: 1. `systemctl stop avahi-daemon` 2. Launch librespot with: ``` while :; do librespot --zeroconf-port=5354 --volume-ctrl=linear --name Snapcast --bitrate 320 --backend pipe --initial-volume 100 --verbose; sleep 0.5; done ``` Librespot fails to start until avahi is started: ``` [2023-03-19T21:02:13Z WARN librespot] Could not initialise discovery: Setting up dns-sd failed: DNS-SD Error: Unknown. [2023-03-19T21:02:13Z ERROR librespot] Discovery is unavailable and no credentials provided. Authentication is not possible. ``` 3. `systemctl start avahi-daemon` Librespot now starts, but the instance is not discoverable until librespot is launched again. Some kind of a race condition? Additionally, restarting avahi-daemon while librespot is running (in a discoverable state) will make it undiscoverable until restarted. Log: ``` [2023-03-19T20:57:14Z INFO librespot] librespot 0.4.2 UNKNOWN (Built on 2023-03-14, Build ID: 315532800, Profile: release) [2023-03-19T20:57:14Z TRACE librespot] Command line argument(s): [2023-03-19T20:57:14Z TRACE librespot] zeroconf-port "5354" [2023-03-19T20:57:14Z TRACE librespot] volume-ctrl "linear" [2023-03-19T20:57:14Z TRACE librespot] name "Snapcast" [2023-03-19T20:57:14Z TRACE librespot] bitrate "320" [2023-03-19T20:57:14Z TRACE librespot] backend "pipe" [2023-03-19T20:57:14Z TRACE librespot] initial-volume "100" [2023-03-19T20:57:14Z TRACE librespot] verbose [2023-03-19T20:57:14Z DEBUG librespot_discovery::server] Zeroconf server listening on 0.0.0.0:5354 *** WARNING *** The program 'librespot' uses the Apple Bonjour compatibility layer of Avahi. *** WARNING *** Please fix your application to use the native API of Avahi! *** WARNING *** For more information see <http://0pointer.de/blog/projects/avahi-compat.html> ``` **Host (what you are running `librespot` on):** - OS: NixOS 22.11 - Platform: x86 ``` # avahi-daemon --version avahi-daemon 0.8 ```
kerem 2026-02-27 19:31:08 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@vlada-dudr commented on GitHub (May 18, 2023):

It is due Librespot implementing it's own mDNS stack instead of just registering with Avahi. So they fight each other.

<!-- gh-comment-id:1552715326 --> @vlada-dudr commented on GitHub (May 18, 2023): It is due Librespot implementing it's own mDNS stack instead of just registering with Avahi. So they fight each other.
Author
Owner

@ettom commented on GitHub (May 18, 2023):

It is due Librespot implementing it's own mDNS stack instead of just registering with Avahi. So they fight each other.

I have compiled librespot with the dns-sd backend. Isn't that supposed to use Avahi for discovery?

<!-- gh-comment-id:1552802661 --> @ettom commented on GitHub (May 18, 2023): > It is due Librespot implementing it's own mDNS stack instead of just registering with Avahi. So they fight each other. I have compiled librespot with the dns-sd backend. Isn't that supposed to use Avahi for discovery?
Author
Owner

@vlada-dudr commented on GitHub (May 18, 2023):

Ok, then it should use avahi. But it probably doesn't retry if avahi is unavailable. One has to correctly order service dependencies in systemd or other supervisor used. Systemd can propagate restarts if configured to do so, but that's only workaround for proper dbus discovery

May 18, 2023 11:42:20 ettom @.***>:

It is due Librespot implementing it's own mDNS stack instead of just registering with Avahi. So they fight each other.

I have compiled librespot with the dns-sd backend. Isn't that supposed to use Avahi for discovery?


Reply to this email directly, view it on GitHub[https://github.com/librespot-org/librespot/issues/1133#issuecomment-1552802661], or unsubscribe[https://github.com/notifications/unsubscribe-auth/ADD33ZLX55QUFCVXIHDXV4LXGXVHZANCNFSM6AAAAAAWAKUYMM].
You are receiving this because you commented.[Tracking image][https://github.com/notifications/beacon/ADD33ZNGUMX2S7JWPE6JDC3XGXVHZA5CNFSM6AAAAAAWAKUYMOWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTS4RXRWK.gif]

<!-- gh-comment-id:1552960968 --> @vlada-dudr commented on GitHub (May 18, 2023): Ok, then it should use avahi. But it probably doesn't retry if avahi is unavailable. One has to correctly order service dependencies in systemd or other supervisor used. Systemd can propagate restarts if configured to do so, but that's only workaround for proper dbus discovery May 18, 2023 11:42:20 ettom ***@***.***>: > > It is due Librespot implementing it's own mDNS stack instead of just registering with Avahi. So they fight each other. > > I have compiled librespot with the dns-sd backend. Isn't that supposed to use Avahi for discovery? > > — > Reply to this email directly, view it on GitHub[https://github.com/librespot-org/librespot/issues/1133#issuecomment-1552802661], or unsubscribe[https://github.com/notifications/unsubscribe-auth/ADD33ZLX55QUFCVXIHDXV4LXGXVHZANCNFSM6AAAAAAWAKUYMM]. > You are receiving this because you commented.[Tracking image][https://github.com/notifications/beacon/ADD33ZNGUMX2S7JWPE6JDC3XGXVHZA5CNFSM6AAAAAAWAKUYMOWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTS4RXRWK.gif] >
Author
Owner

@ettom commented on GitHub (May 18, 2023):

I have set Requires=avahi-daemon.service on the librespot service and it doesn't really work (see my original post). I could try to create a workaround like adding a small delay in ExecStartPre for librespot.service, but I think this should not be required and librespot should handle it internally.

<!-- gh-comment-id:1553720505 --> @ettom commented on GitHub (May 18, 2023): I have set `Requires=avahi-daemon.service` on the librespot service and it doesn't really work (see my original post). I could try to create a workaround like adding a small delay in `ExecStartPre` for librespot.service, but I think this should not be required and librespot should handle it internally.
Author
Owner

@vlada-dudr commented on GitHub (May 19, 2023):

The problem is though that librespot doesn't listen to events from avahi, so in case of avahi is restarted librespot never applies again for registration. This is caused by librespot using only simple (and deprecated) compatibility bindings to Avahi.

Other issue is that Requires pull dependency in whenever librespot start, but it doesn't order them anyhow. To have librespot started after avahi add After=avahi-daemon.service (or socket might be cleaner). You can also work around the registration issue by using BindsTo=avahi-daemon.service instead Requires , which will start and stop (and restart) librespot in concert with Avahi. The ordering is still done through After.

<!-- gh-comment-id:1554505546 --> @vlada-dudr commented on GitHub (May 19, 2023): The problem is though that librespot doesn't listen to events from avahi, so in case of avahi is restarted librespot never applies again for registration. This is caused by librespot using only simple (and deprecated) compatibility bindings to Avahi. Other issue is that `Requires` pull dependency in whenever librespot start, but it doesn't order them anyhow. To have librespot started after avahi add `After=avahi-daemon.service` (or socket might be cleaner). You can also work around the registration issue by using `BindsTo=avahi-daemon.service` instead `Requires` , which will start and stop (and restart) librespot in concert with Avahi. The ordering is still done through `After`.
Author
Owner

@headblockhead commented on GitHub (Apr 6, 2024):

For anyone coming across this in the future, I have found that a similar issue (librespot fully undiscoverable) was resolved for me by enabling publishing / user service publishing in avahi's config.

For some reason this is disabled by default! Took me way too long to figure out :P

In NixOS:

services.avahi = {
  enable = true;
  publish = {
    enable = true;
    userServices = true;
  };
};

Sorry for interrupting / necroposting as this doesn't resolve the issue but this is the (only) top google result for DNS-SD Error: Unknown. and I didn't want to create a new issue for a problem I already fixed myself.

Feel free to hide/delete this post if you want!

<!-- gh-comment-id:2041229773 --> @headblockhead commented on GitHub (Apr 6, 2024): For anyone coming across this in the future, I have found that a similar issue (librespot fully undiscoverable) was resolved for me by enabling publishing / user service publishing in `avahi`'s config. For some reason this is disabled by default! Took me way too long to figure out :P In NixOS: ```nix services.avahi = { enable = true; publish = { enable = true; userServices = true; }; }; ``` Sorry for interrupting / necroposting as this doesn't resolve the issue but this is the (only) top google result for `DNS-SD Error: Unknown.` and I didn't want to create a new issue for a problem I already fixed myself. Feel free to hide/delete this post if you want!
Author
Owner

@roderickvd commented on GitHub (Oct 26, 2024):

You can now configure librespot to use the Avahi daemon.

<!-- gh-comment-id:2439615442 --> @roderickvd commented on GitHub (Oct 26, 2024): You can now configure librespot to use the Avahi daemon.
Author
Owner

@roderickvd commented on GitHub (Oct 26, 2024):

See #1347 or launch librespot with -h to get a list of options.

<!-- gh-comment-id:2439669435 --> @roderickvd commented on GitHub (Oct 26, 2024): See #1347 or launch librespot with -h to get a list of options.
Author
Owner

@wisp3rwind commented on GitHub (Oct 29, 2024):

To elaborate on what @roderickvd said: The old dns-sd backend is unchanged and still has this issue.

However, there's a new backend which requires compiling with the with-avahi feature (it should become the default then). This backend listens on DBus for Avahi to show up, and only then registers the service. It should also deal with Avahi daemon restarts.

<!-- gh-comment-id:2443680218 --> @wisp3rwind commented on GitHub (Oct 29, 2024): To elaborate on what @roderickvd said: The old `dns-sd` backend is unchanged and still has this issue. However, there's a new backend which requires compiling with the `with-avahi` feature (it should become the default then). This backend listens on DBus for Avahi to show up, and only then registers the service. It should also deal with Avahi daemon restarts.
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#531
No description provided.