[avahi] avahi caching prevents detection of re-appearing services

Johannes Overmann Johannes.Overmann at gmx.de
Thu Oct 31 12:37:42 CET 2013

Hi all,

I am using avahi to discover services of a specific kind. I am aware that mDNS is in practice not suitable in detecting when services go away, for example because devices simply get switched off and have no chance to send a good bye mDNS message. This is OK for me, as I can detect whether a service is alive or not by simply trying to use it and silently ignoring it when it is reported by avahi but does not respond at all.

Specifically what I am seeing is that a service which was there and which I just unplugged, still appears when browsing services, but does not appear when resolving services. The service resolver says 'Timeout reached' after about 4 seconds. This seems sensible.

Now the problem:
When this service is added to the network again (for example by pluging the device back in), sending out all the necessary mDNS messages, then my application does _not_ get notified through the service browser that there is a new service. I assume this is because for avahi this service is still in the cache. This is quite bad since my application is not notified about this event even though the device sends out all the necessary mDNS info. Avahi is essentially hiding this event information from me due to its cache.

Is there a way to programmatically tell avahi to drop a certain service from the cache?
Is there a way to tell avahi to automatically drop services from the cache which cannot be resolved? (This would make a lot of sense to me and would the the above problem.)
Is there a way to programmatically tell avahi to flush its entire cache?
Is there a way to programmatically modify the ttl of cache entries? If so I would change the ttl of an unresolvable entry to 1s.

At the moment I am down to kill and restart the avahi-daemon whenever a browsable service fails to resolve. This makes it possible to detect the same service appearing again later.

The only alternative I can think of would be to _poll_ for browsable yet not resolvable services which cannot be in the spritit of mDNS or avahi, since they try to solve exactly this problem.

Any help on this appreciated.


Johannes.Overmann at gmx.de (http://overmann-consulting.de)

Johannes.Overmann at gmx.de (http://overmann-consulting.de)

More information about the avahi mailing list