What is the expected behavior when a node having registered some service dies before having a chance to unregister it?
Looks like this service is never seen as removed (through ServiceListener) while it is no more listed.
Is there some timeout?
Also restarting the crashed node doesn't generate new ServiceListener events (but this might be a side effect of removed never been called).
Yes there is a time out. The timeout is fixed by the spec to 1 hour, so if the node comes back before the expiry the removal will not be seen.
Any chance this timeout can be tweaked? (even if it's not spec compliant)
The value is the DNSConstants, but this will only apply to node using JmDNS. the wait this works is that when you register a service with mDNS you include a time to live (TTL). all other node will listen to announcements and cache the value for the TTL, if your node crashes there is nothing you could do. The mDNS protocol is just not designed as a watch dog. It is fundamentally a DNS protocol to find resources on the network not a mean to determine resource availability.
In our case JmDNS is used for both announcement and discovery and no other system is supposed to interact.
Right now we simulate listener mechanism by monitoring values returned by JmDNS#list. I was hopping to rely on the native listener mechanism but I understand this is not mDNS protocol's purpose.
I don't think the list will be right either. List uses some cached information if available. After discovery, I would do one of two things to keep track of nodes either implement a "ping" using some service call outside of JmDNS or if you are only interested in the restart you could have a start counter in the text value of the service. As the value of the text service record changes JmDNS should call a service resolved listener. To keep it simple I would suggest to have a field "startdate" and put the value of the system time in there. Like that at each restart the value will change and the listener will be called.
Second option sounds interesting. I will investigate it.