Avahi-observe interface not autoconnecting and libavahi-client crashing on it

Hey folks, I’m trying to snap up nymea:app which uses zeroconf to find nymea boxes in the network. One issue I’m facing is that in order for zeroconf to work, one needs to have the avahi-observe plug/slot connected which is not an autoconnected one at this time.

This wouldn’t be a bit issue as the app could fallback to UPnP if zeroconf isn’t available. However, in this setup, everything seems like avahi is available, we can load the libavahi-client lib and all, but when it actually starts, it asserts and the app just crashes…

That means, if someone installs my snap and does not manually and explicitly connect the dots, the app will just crash and it’s not exactly easy to prevent that from an app developer point of view as it happens inside libavahi-client.

While auto-connecting avahi-observe would be a workaround for the crash-experience, on the other hand this seems to render the avahi-observe permission rather useless given a user can never turn it off, or avahi-powered apps won’t start any more.

What would you suggest to improve that situation?

For your snap, it seems like requesting auto-connection makes the most sense.

As for improving the situation generally, it seems like the snap (and based on your description, libavahi-client) arguably has a bug. IMHO, the snap should detect if it has the necessary permissions before trying out something and crashing. Once connection hooks are in place, I think you’ll be able to know if avahi-observe is connected or not, and make an intelligent decision. @pstolowski may have more details or suggestions.

Indeed, with interface hooks you can have a meta/hooks/connect-plug-<plugname> hook (a script) that gets called when the connection is created and ready, and you can trigger any custom logic from there to let you application know about that.