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

Already on GitHub? Sign in to your account

Fix event listener leak check timing #1041

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

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 join this conversation on GitHub. Already have an account? Sign in to comment