homebridge / ciao

RFC 6762 and RFC 6763 compliant mdns service discovery library written in Typescript
MIT License
81 stars 6 forks source link

Race condition when unpublishing service immediately after advertising #18

Open Supereg opened 3 years ago

Supereg commented 3 years ago

Describe The Bug: When removing the advertisement for a ciao service immediately after advertising it, it may result in a race condition. It seems like the Prober isn't properly canceled (or rather started after the service advertisement has already been ended). Therefore the Prober accesses an already closed MDNSServer.

To Reproduce:

  1. Create a CiaoService service.
  2. Call service.advertise()
  3. Call service.destroy() or service()

Expected behavior: The Responder should not start a probing step when the service was already unannounced.

Logs:

The reported error is as follows:

Cannot send packets on a closed mdns server!
ERR_SERVER_CLOSED: Cannot send packets on a closed mdns server!
    at MDNSServer.assertBeforeSend (/Users/andi/Documents/WebstormProjects/HAP-NodeJS/node_modules/@homebridge/ciao/src/MDNSServer.ts:403:13)
    at MDNSServer.sendOnAllNetworksForService (/Users/andi/Documents/WebstormProjects/HAP-NodeJS/node_modules/@homebridge/ciao/src/MDNSServer.ts:302:10)
    at MDNSServer.sendQueryBroadcast (/Users/andi/Documents/WebstormProjects/HAP-NodeJS/node_modules/@homebridge/ciao/src/MDNSServer.ts:263:26)
    at Prober.sendProbeRequest (/Users/andi/Documents/WebstormProjects/HAP-NodeJS/node_modules/@homebridge/ciao/src/responder/Prober.ts:165:17)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)

Environment:

Supereg commented 2 years ago

Closed by accident.