From 972eafd9835e46516f50e37486cd8bb2ef81a714 Mon Sep 17 00:00:00 2001 From: sinkhaha <1468709106@qq.com> Date: Mon, 13 May 2024 02:16:09 +0800 Subject: [PATCH] events: update MaxListenersExceededWarning message log PR-URL: https://github.com/nodejs/node/pull/51921 Reviewed-By: Moshe Atlow Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca --- lib/events.js | 2 +- lib/internal/event_target.js | 2 +- .../test-event-emitter-max-listeners-warning-for-null.js | 2 +- .../test-event-emitter-max-listeners-warning-for-symbol.js | 2 +- test/parallel/test-event-emitter-max-listeners-warning.js | 2 +- test/parallel/test-eventtarget-memoryleakwarning.js | 5 ++++- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/events.js b/lib/events.js index b8290619408390..d0f0173ecae8eb 100644 --- a/lib/events.js +++ b/lib/events.js @@ -592,7 +592,7 @@ function _addListener(target, type, listener, prepend) { // No error code for this since it is a Warning const w = genericNodeError( `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 }); process.emitWarning(w); } diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 94a257062147f8..0ebba99f351808 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -565,7 +565,7 @@ class EventTarget { // eslint-disable-next-line no-restricted-syntax const w = new Error('Possible EventTarget memory leak detected. ' + `${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'); w.name = 'MaxListenersExceededWarning'; w.target = this; diff --git a/test/parallel/test-event-emitter-max-listeners-warning-for-null.js b/test/parallel/test-event-emitter-max-listeners-warning-for-null.js index 40b5f798cbadb0..81cfc96f43a32d 100644 --- a/test/parallel/test-event-emitter-max-listeners-warning-for-null.js +++ b/test/parallel/test-event-emitter-max-listeners-warning-for-null.js @@ -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].')); + '2 null listeners added to [EventEmitter]. MaxListeners is 1.')); })); e.on(null, () => {}); diff --git a/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js b/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js index c27b38c2523453..212f9fb1b27a0a 100644 --- a/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js +++ b/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js @@ -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].')); + '2 Symbol(symbol) listeners added to [EventEmitter]. MaxListeners is 1.')); })); e.on(symbol, () => {}); diff --git a/test/parallel/test-event-emitter-max-listeners-warning.js b/test/parallel/test-event-emitter-max-listeners-warning.js index 3d047766b38fd9..fc23355349ef79 100644 --- a/test/parallel/test-event-emitter-max-listeners-warning.js +++ b/test/parallel/test-event-emitter-max-listeners-warning.js @@ -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].')); + '2 event-type listeners added to [FakeInput]. MaxListeners is 1.')); })); e.on('event-type', () => {}); diff --git a/test/parallel/test-eventtarget-memoryleakwarning.js b/test/parallel/test-eventtarget-memoryleakwarning.js index 36fe068fb806d6..b2da553ab4cacb 100644 --- a/test/parallel/test-eventtarget-memoryleakwarning.js +++ b/test/parallel/test-eventtarget-memoryleakwarning.js @@ -12,18 +12,21 @@ const { setTimeout } = require('timers/promises'); common.expectWarning({ MaxListenersExceededWarning: [ ['Possible EventTarget memory leak detected. 3 foo listeners added to ' + - 'EventTarget. Use events.setMaxListeners() ' + + 'EventTarget. MaxListeners is 2. Use events.setMaxListeners() ' + 'to increase limit'], ['Possible EventTarget memory leak detected. 3 foo listeners added to ' + '[MessagePort [EventTarget]]. ' + + 'MaxListeners is 2. ' + 'Use events.setMaxListeners() to increase ' + 'limit'], ['Possible EventTarget memory leak detected. 3 foo listeners added to ' + '[MessagePort [EventTarget]]. ' + + 'MaxListeners is 2. ' + 'Use events.setMaxListeners() to increase ' + 'limit'], ['Possible EventTarget memory leak detected. 3 foo listeners added to ' + '[AbortSignal]. ' + + 'MaxListeners is 2. ' + 'Use events.setMaxListeners() to increase ' + 'limit'], ],