Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Fix event listener leak check timing #1041

Closed
wants to merge 1 commit into from
Closed

Fix event listener leak check timing #1041

wants to merge 1 commit into from

Conversation

koichik
Copy link

@koichik koichik commented May 12, 2011

Because check for listener leak is performed before the listener was added to an array, the warning occurred the 12th listener not the 11th listener.

Reproduce:

$ cat leak.js
var events = require('events');
var emitter = new events.EventEmitter();
for (var i = 0; i < 10; ++i) {
  emitter.on('data', function() {});
}
console.log('added 10 listeners');
console.log('adding 11th listener');
emitter.on('data', function() {});
console.log('adding 12th listener');
emitter.on('data', function() {});

$ node leak.js
added 10 listeners
adding 11th listener
adding 12th listener
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace: 
    at EventEmitter.<anonymous> (events.js:123:17)
    at Object.<anonymous> (/tmp/leak.js:10:9)
    at Module._compile (module.js:404:26)
    at Object..js (module.js:410:10)
    at Module.load (module.js:336:31)
    at Function._load (module.js:297:12)
    at Array.0 (module.js:423:10)
    at EventEmitter._tickCallback (node.js:126:26)

@ry ry closed this in 80c2fe9 May 14, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants