keepsimple1 / mdns-sd

Rust library for mDNS based Service Discovery
Apache License 2.0
96 stars 37 forks source link

fix PTR expiration preventing later service resolution #140

Closed Mornix closed 11 months ago

Mornix commented 11 months ago

Hi,

I ran across this issue while using mdns-sd when browsing for a specific service domain. The bug requires the following message pattern to manifest:

  1. Remote end sends an announcement (PTR+SRV+TXT) -- mdns-sd correctly emits ServiceFound and ServiceResolved
  2. Remote end sends an invalidation for only the PTR (setting TTL to zero) -- mdns-sd correctly emits ServiceRemoved
  3. Remote end sends an announcement (PTR+SRV+TXT) before any of the SRV, TXT, A, or AAAA records expire -- mdns-sd emits ServiceFound but does not emit ServiceResolved

From my understanding of the code, it looks like it assumes that a new SRV or TXT (or another non-PTR) record will be received after a new PTR relying on that to trigger the block responsible for resolving the service.

I've added a test (in the place of least resistance) that reproduces this behaviour.