From 802e6be4c7e2bfd08224fb6769fbe7b2d8ed0239 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 27 Aug 2016 10:45:34 +0200 Subject: [PATCH 1/2] events: make memory leak warning more accessible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the famous `EventEmitter memory leak` warnings occurring when the listener count for a given event exceeds a specified number more programatically accessible, by giving them properties referring to the event emitter instance and the event itself. This can be useful for debugging the origins of such a warning when the stack itself doesn’t reveal enough information about the event emitter instance itself, e.g. when manual inspection of the already-registered listeners is expected to be useful. --- doc/api/events.md | 6 ++++++ lib/events.js | 7 ++++++- ...est-event-emitter-max-listeners-warning.js | 21 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-event-emitter-max-listeners-warning.js diff --git a/doc/api/events.md b/doc/api/events.md index eab0bef17ed199..92b7bbd38c2162 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -278,6 +278,11 @@ emitter.once('event', () => { }); ``` +The emitted warning can be inspected with [`process.on('warning')`][] and will +have the additional `emitter`, `type` and `count` properties, referring to +the event emitter instance, the event’s name and the number of attached +listeners, respectively. + ### emitter.addListener(eventName, listener)