forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
events: make memory leak warning more accessible
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: nodejs#8298 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <Fishrock123@rocketmail.com>
- Loading branch information
Showing
3 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Flags: --no-warnings | ||
// The flag suppresses stderr output but the warning event will still emit | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const events = require('events'); | ||
const assert = require('assert'); | ||
|
||
const e = new events.EventEmitter(); | ||
e.setMaxListeners(1); | ||
|
||
process.on('warning', common.mustCall((warning) => { | ||
assert.ok(warning instanceof Error); | ||
assert.strictEqual(warning.name, 'Warning'); | ||
assert.strictEqual(warning.emitter, e); | ||
assert.strictEqual(warning.count, 2); | ||
assert.strictEqual(warning.type, 'event-type'); | ||
})); | ||
|
||
e.on('event-type', function() {}); | ||
e.on('event-type', function() {}); |