events: update MaxListenersExceededWarning message log

PR-URL: https://github.com/nodejs/node/pull/51921
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
pull/52971/head
sinkhaha 2024-05-13 02:16:09 +08:00 committed by Michaël Zasso
parent fca38b2d6e
commit ca5607bbc8
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
6 changed files with 9 additions and 6 deletions

View File

@ -593,7 +593,7 @@ function _addListener(target, type, listener, prepend) {
// No error code for this since it is a Warning // No error code for this since it is a Warning
const w = genericNodeError( const w = genericNodeError(
`Possible EventEmitter memory leak detected. ${existing.length} ${String(type)} listeners ` + `Possible EventEmitter memory leak detected. ${existing.length} ${String(type)} listeners ` +
`added to ${inspect(target, { depth: -1 })}. Use emitter.setMaxListeners() to increase limit`, `added to ${inspect(target, { depth: -1 })}. MaxListeners is ${m}. Use emitter.setMaxListeners() to increase limit`,
{ name: 'MaxListenersExceededWarning', emitter: target, type: type, count: existing.length }); { name: 'MaxListenersExceededWarning', emitter: target, type: type, count: existing.length });
process.emitWarning(w); process.emitWarning(w);
} }

View File

@ -561,7 +561,7 @@ class EventTarget {
// eslint-disable-next-line no-restricted-syntax // eslint-disable-next-line no-restricted-syntax
const w = new Error('Possible EventTarget memory leak detected. ' + const w = new Error('Possible EventTarget memory leak detected. ' +
`${size} ${type} listeners ` + `${size} ${type} listeners ` +
`added to ${inspect(this, { depth: -1 })}. Use ` + `added to ${inspect(this, { depth: -1 })}. MaxListeners is ${this[kMaxEventTargetListeners]}. Use ` +
'events.setMaxListeners() to increase limit'); 'events.setMaxListeners() to increase limit');
w.name = 'MaxListenersExceededWarning'; w.name = 'MaxListenersExceededWarning';
w.target = this; w.target = this;

View File

@ -16,7 +16,7 @@ process.on('warning', common.mustCall((warning) => {
assert.strictEqual(warning.count, 2); assert.strictEqual(warning.count, 2);
assert.strictEqual(warning.type, null); assert.strictEqual(warning.type, null);
assert.ok(warning.message.includes( assert.ok(warning.message.includes(
'2 null listeners added to [EventEmitter].')); '2 null listeners added to [EventEmitter]. MaxListeners is 1.'));
})); }));
e.on(null, () => {}); e.on(null, () => {});

View File

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

View File

@ -23,7 +23,7 @@ process.on('warning', common.mustCall((warning) => {
assert.strictEqual(warning.count, 2); assert.strictEqual(warning.count, 2);
assert.strictEqual(warning.type, 'event-type'); assert.strictEqual(warning.type, 'event-type');
assert.ok(warning.message.includes( assert.ok(warning.message.includes(
'2 event-type listeners added to [FakeInput].')); '2 event-type listeners added to [FakeInput]. MaxListeners is 1.'));
})); }));
e.on('event-type', () => {}); e.on('event-type', () => {});

View File

@ -12,18 +12,21 @@ const { setTimeout } = require('timers/promises');
common.expectWarning({ common.expectWarning({
MaxListenersExceededWarning: [ MaxListenersExceededWarning: [
['Possible EventTarget memory leak detected. 3 foo listeners added to ' + ['Possible EventTarget memory leak detected. 3 foo listeners added to ' +
'EventTarget. Use events.setMaxListeners() ' + 'EventTarget. MaxListeners is 2. Use events.setMaxListeners() ' +
'to increase limit'], 'to increase limit'],
['Possible EventTarget memory leak detected. 3 foo listeners added to ' + ['Possible EventTarget memory leak detected. 3 foo listeners added to ' +
'[MessagePort [EventTarget]]. ' + '[MessagePort [EventTarget]]. ' +
'MaxListeners is 2. ' +
'Use events.setMaxListeners() to increase ' + 'Use events.setMaxListeners() to increase ' +
'limit'], 'limit'],
['Possible EventTarget memory leak detected. 3 foo listeners added to ' + ['Possible EventTarget memory leak detected. 3 foo listeners added to ' +
'[MessagePort [EventTarget]]. ' + '[MessagePort [EventTarget]]. ' +
'MaxListeners is 2. ' +
'Use events.setMaxListeners() to increase ' + 'Use events.setMaxListeners() to increase ' +
'limit'], 'limit'],
['Possible EventTarget memory leak detected. 3 foo listeners added to ' + ['Possible EventTarget memory leak detected. 3 foo listeners added to ' +
'[AbortSignal]. ' + '[AbortSignal]. ' +
'MaxListeners is 2. ' +
'Use events.setMaxListeners() to increase ' + 'Use events.setMaxListeners() to increase ' +
'limit'], 'limit'],
], ],