Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

events: update MaxListenersExceededWarning message log #51921

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ function _addListener(target, type, listener, prepend) {
existing.warned = true;
// No error code for this since it is a Warning
const w = genericNodeError(
`Possible EventEmitter memory leak detected. ${existing.length} ${String(type)} listeners ` +
`Possible EventEmitter memory leak detected. MaxListeners is ${m}. ${existing.length} ${String(type)} listeners ` +
`added to ${inspect(target, { depth: -1 })}. Use emitter.setMaxListeners() to increase limit`,
{ name: 'MaxListenersExceededWarning', emitter: target, type: type, count: existing.length });
process.emitWarning(w);
Expand Down
1 change: 1 addition & 0 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ class EventTarget {
// No error code for this since it is a Warning
// eslint-disable-next-line no-restricted-syntax
const w = new Error('Possible EventTarget memory leak detected. ' +
`MaxListeners is ${this[kMaxEventTargetListeners]}. ` +
`${size} ${type} listeners ` +
`added to ${inspect(this, { depth: -1 })}. Use ` +
'events.setMaxListeners() to increase limit');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ process.on('warning', common.mustCall((warning) => {
assert.strictEqual(warning.count, 2);
assert.strictEqual(warning.type, null);
assert.ok(warning.message.includes(
'2 null listeners added to [EventEmitter].'));
'MaxListeners is 1. 2 null listeners added to [EventEmitter].'));
}));

e.on(null, () => {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ process.on('warning', common.mustCall((warning) => {
assert.strictEqual(warning.count, 2);
assert.strictEqual(warning.type, symbol);
assert.ok(warning.message.includes(
'2 Symbol(symbol) listeners added to [EventEmitter].'));
'MaxListeners is 1. 2 Symbol(symbol) listeners added to [EventEmitter].'));
}));

e.on(symbol, () => {});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-event-emitter-max-listeners-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ process.on('warning', common.mustCall((warning) => {
assert.strictEqual(warning.count, 2);
assert.strictEqual(warning.type, 'event-type');
assert.ok(warning.message.includes(
'2 event-type listeners added to [FakeInput].'));
'MaxListeners is 1. 2 event-type listeners added to [FakeInput].'));
}));

e.on('event-type', () => {});
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-eventtarget-memoryleakwarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ const { setTimeout } = require('timers/promises');

common.expectWarning({
MaxListenersExceededWarning: [
['Possible EventTarget memory leak detected. 3 foo listeners added to ' +
['Possible EventTarget memory leak detected. MaxListeners is 2. 3 foo listeners added to ' +
'EventTarget. Use events.setMaxListeners() ' +
'to increase limit'],
['Possible EventTarget memory leak detected. 3 foo listeners added to ' +
['Possible EventTarget memory leak detected. MaxListeners is 2. 3 foo listeners added to ' +
'[MessagePort [EventTarget]]. ' +
'Use events.setMaxListeners() to increase ' +
'limit'],
['Possible EventTarget memory leak detected. 3 foo listeners added to ' +
['Possible EventTarget memory leak detected. MaxListeners is 2. 3 foo listeners added to ' +
'[MessagePort [EventTarget]]. ' +
'Use events.setMaxListeners() to increase ' +
'limit'],
['Possible EventTarget memory leak detected. 3 foo listeners added to ' +
['Possible EventTarget memory leak detected. MaxListeners is 2. 3 foo listeners added to ' +
'[AbortSignal]. ' +
'Use events.setMaxListeners() to increase ' +
'limit'],
Expand Down
Loading