Description
Specification
Right now in certain cases we have an EventTarget
or a AbortSignal
which has many registered listeners. Usually when multiple children classes need to listen to a parent. EG, multiple QUICConnection
s per QUICServer
, or multiple QUICStream
s per QUICConnection
. By default, when we exceed 11 listeners we get the following warning.
> (node:61422) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 foo listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
Currently this has been addressed in two locations with the following.
QUICServer.ts 379: nodesEvents.setMaxListeners(100000, this.stopAbortController.signal); QUICSocket.ts 254: nodesEvents.setMaxListeners(100000, this[_eventTarget]);
But we want to standardise how this is generally done and avoid magic numbers in random places in the code. The limit should also configurable in some way. At the very least the nodesEvents.setMaxListeners
should be moved into a utility function to avoid spreading out the magic.
Additional context
Relevant discussion: https://github.com/MatrixAI/js-quic/pull/104/files#r1626356768
Tasks
- The
nodesEvents.setMaxListeners
usage should be standardised and quarantined into a utility function. - The limit should come from a config parameter in some way.