From 932c824c600167d3057d3b42b6b0b81468334efb Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 27 Aug 2016 10:45:34 +0200 Subject: [PATCH] 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. PR-URL: https://github.com/nodejs/node/pull/8298 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel --- doc/api/events.md | 10 +++++++++ lib/events.js | 7 ++++++- ...est-event-emitter-max-listeners-warning.js | 21 +++++++++++++++++++ 3 files changed, 37 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..6b19287881c132 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -278,6 +278,14 @@ emitter.once('event', () => { }); ``` +The [`--trace-warnings`][] command line flag can be used to display the +stack trace for such warnings. + +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)