Decache A Module That Adds Event Listeners
- Dominant language
- JavaScript
- Stars
- 153
- Forks
- 12
- PR merge metrics
- No merged PRs in 30d
Description
It seems there is an issue when decaching a module that listens to events. I have a logging module that is used from everywhere. It leverages `winston`, which adds event listeners so that it can log for `uncaughtException`. However, when I decache a module and load it again for testing, the logging module is also reloaded, which re-adds all the `winston` loggers, which adds all the event listeners again. However, as far as `process` is concerned these listeners are already bound, so they just accumulate and I get the warning: `(node) warning: possible EventEmitter memory leak detected. 11 uncaughtException listeners added. Use emitter.setMaxListeners() to increase limit.`
I wonder what the correct process is for handling this case. Could it be that a function is called just before decching that would allow some custom code to unregister these listeners (`winston.clear()`)?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.