High number of event handlers problematic?

223 views
Skip to first unread message

Felix E. Klee

unread,
Nov 15, 2012, 4:21:32 AM11/15/12
to nod...@googlegroups.com
Node reports:

(node) warning: possible EventEmitter memory leak detected. 11
listeners added. Use emitter.setMaxListeners() to increase limit.

That there are more than 10 event listeners in my app is no surprise:
For every Socket.IO socket, I set up `n` listeners on "connect" to the
Redis database. The number `n` is around 10 (it corresponds to the
number of certain Redis keys).

To sum up, with every client (browser) connect, about 10 listeners for
the Redis "connect" event are added. So in the end, there may be
thousands of listeners for the Redis "connect" event.

I'd like to keep it that way, as the solution appears simple and robust.

However the above warning makes me suspicious: Is the solution no so
robust after all? Are there potential problems?

Or could I just do `emitter.setMaxListeners(0)`, and that's it?

Ben Noordhuis

unread,
Nov 15, 2012, 8:45:25 AM11/15/12
to nod...@googlegroups.com
Don't read too much into it, it's just a warning. If you have a
legitimate reason to add 10+ listeners, go ahead and increase
maxListeners.

Fedor Indutny

unread,
Nov 15, 2012, 8:48:37 AM11/15/12
to nod...@googlegroups.com
It's very roboust, it's just to debug event listener leaks, which may happen if you're attaching the same listener to the same event emitter over and over again.

Cheers,
Fedor.




--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Felix E. Klee

unread,
Nov 15, 2012, 4:40:27 PM11/15/12
to nod...@googlegroups.com
On Thu, Nov 15, 2012 at 2:48 PM, Fedor Indutny <fe...@indutny.com>
wrote:
> it's just to debug event listener leaks, which may happen
> if you're attaching the same listener to the same event emitter over and
> over again.

I just set `redisClient.setMaxListeners(0)`, until I thought again, and:

That warning actually makes sense! My app does have a leak:

The problem is that new event listeners are added on every Socket.IO
connection (= browser connection). But: When a browser disconnects, then
that is not registered, and the listeners persist. Now I wonder how to
avoid that problem:

https://groups.google.com/forum/#!topic/socket_io/S5G6f4YJdvo
Reply all
Reply to author
Forward
0 new messages