First, the methods start and stop of class MulticastDNS specify different handler functions for adding an event listener in start and removing this listener in stop. In effect, the added listeners are never removed, as (event) => this._onMdnsQuery(event) and this._onMdnsQuery are two completely different functions that are not reference-equal!
Second, the second invocation of removeListener in the stop method (line 88) should target the response event, not the query event.
This is how the buggy code looks like (with console.log annotations on listener count). The listener count is still 1 after stop method has run.
First, the methods
start
andstop
of classMulticastDNS
specify different handler functions for adding an event listener instart
and removing this listener instop
. In effect, the added listeners are never removed, as(event) => this._onMdnsQuery(event)
andthis._onMdnsQuery
are two completely different functions that are not reference-equal!Second, the second invocation of
removeListener
in thestop
method (line 88) should target theresponse
event, not thequery
event.This is how the buggy code looks like (with console.log annotations on listener count). The listener count is still 1 after
stop
method has run.This is the correct way to fix both bugs:
Thanks for providing a patch release! Hubertus