Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. #2

Open
ymettier opened this issue Dec 17, 2014 · 0 comments

Comments

@ymettier
Copy link

Hello,

I'm using perfmon node module and when I run my js with node --debug, I get an error message starting like this :

$ node --debug --harmony myscript.js
debugger listening on port 5858
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at TypePerf.addListener (events.js:160:15)
    at PerfmonStream.attach (c:\myproject\node_modules\perfmon\lib\PerfmonStream.js:19:11)
[...]

Important note : I call many times perfmon("\\some perf\counter", ...) and that's why I probably need more than 10 listeners.

A short hack is to use setMaxListeners(0) (no limit) like this :

diff --git a/node_modules/perfmon/lib/TypePerf.js b/node_modules/perfmon/lib/TypePerf.js
index a8db4eb..8437c81 100755
--- a/node_modules/perfmon/lib/TypePerf.js
+++ b/node_modules/perfmon/lib/TypePerf.js
@@ -5,6 +5,7 @@ var os = require('os');

 function TypePerf(host, counters) {
        Stream.call(this);
+       this.setMaxListeners(0);

        this.host = host;
        this.cp = [];

Is that a good hack ?

  • no because having a limit helps the developer notice memory leaks
  • yes because in that specific case, the developer (like me) may need more listeners than the default limit and perfmon is not supposed to guess how many listeners I need.

Maybe a better solution is to have perfmon count the number of perf counters it monitors and increase the limit automatically ?

Maybe a better solution is to provide an API to the developer so he can set the number of listeners himself ?

What do you think ?

Regards,
Yves

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant