Fixes EventEmitter leak in AudioService related to _resetNoDataInterval #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes EventEmitter leak in AudioService related to _resetNoDataInterval
Summary
Fixes an EventEmitter leak in AudioService by preventing the
_resetNoDataInterval
callback from being registered multiple times.Motivation
In my current setup, silence detection kicks in to restart the mic instance periodically. This has been fine for my use case; however, after a small number of those, I get warnings about an EventEmitter leak.
note: for testing, I set NO_DATA_INTERVAL_SEC to 1 and set
inputDevice
in the config to something that didn't existDescription of problem
In the
AudioService
class, when adata
event hasn't been emitted forNO_DATA_INTERVAL_SEC
seconds,AudioService.restart()
is invoked.In the
#restart
method, the following two lines interact to result in the emitter leak:In
#_rebindDataListenerCallbacks
, all callbacks that were registered using theAudioService.onData
method are re-applied to the (new) mic instance. More specifically, the callbacks are registered on the mic'saudioStream
(which is calledIsSilence
in the library code)This by itself is fine, but in
#listenForMicInputEvents
the callback to reset the silence detection interval is registered using theonData
method, resulting it in getting re-added to the persistent callback list.This means that if
restart
is called for the 10th time, theresetNoDataInterval
callback will be re-registered ten times on that turn.Explanation of solution
Rather than adding
#_resetNoDataInterval
to a persistent list of callbacks to be re-registered every restart, this PR instead leaves the callback out of the list and instead registers it directly with the mic'saudioStream
component.