doxout/recluster

possible EventEmitter memory leak detected

maxvipon opened this issue · 5 comments

I have a lot of such messages in stderr.log:

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at EventEmitter.addListener (events.js:175:15)
    at module.exports.self.reload.i (/usr/lib/frontend/server/node_modules/recluster/index.js:230:21)
    at Array.forEach (native)
    at EventEmitter.module.exports.self.reload (/usr/lib/frontend/server/node_modules/recluster/index.js:211:22)
    at process.<anonymous> (/usr/lib/frontend/server/index.js:53:13)
    at process.EventEmitter.emit (events.js:93:17)
    at SignalWatcher.startup.processSignalHandlers.process.on.process.addListener.w.callback (node.js:487:45)

/usr/lib/frontend/server/index.js:53:13

51    process.on('SIGUSR2', function() {
52        console.log('%s [master] Got SIGUSR2, reloading cluster...', prefix);
53        cluster.reload();
54    });

Possible It will be enough to set emitter.setMaxListeners(options.workers)

Probably not. Are you by any chance utilizing the callback argument of reload() ?

Edit: I tried writing a test to reproduce this and failed... hrm.

From doc: By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default which helps finding memory leaks. Obviously not all Emitters should be limited to 10. This function allows that to be increased. Set to zero for unlimited.

This error can be easily reproduced, if the amount of workers is more than 10

Oh I see. I was looking for leaky listeners, it didn't occur to me that the number of workers could be the reason :) Thank you.

You're welcome (:

Cheers for fixing this - I literally ran into this today and was about to write a PR.

Thanks guys.