Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undiscoverable when launched at the same time as avahi-daemon #1133

Closed
ettom opened this issue Mar 19, 2023 · 9 comments
Closed

Undiscoverable when launched at the same time as avahi-daemon #1133

ettom opened this issue Mar 19, 2023 · 9 comments
Labels

Comments

@ettom
Copy link

ettom commented Mar 19, 2023

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
@ettom ettom added the bug label Mar 19, 2023
@vlada-dudr
Copy link

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

@ettom
Copy link
Author

ettom commented 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?

@vlada-dudr
Copy link

vlada-dudr commented May 18, 2023 via email

@ettom
Copy link
Author

ettom commented 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.

@vlada-dudr
Copy link

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.

@headblockhead
Copy link

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!

@roderickvd
Copy link
Member

You can now configure librespot to use the Avahi daemon.

@roderickvd
Copy link
Member

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

@wisp3rwind
Copy link
Contributor

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants