Skip to content

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

@ymettier

Description

@ymettier

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions