(node:125008) MaxListenersExceededWarning: Possible EventEmitter memory leak detected

Viewed 9630

(node:125008) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 ready listeners added. Use emitter.setMaxListeners() to increase limit

How exactly do I increase the number of listener events? I've searched around and none of the methods I've tried have worked : (

3 Answers

This is explained in the manual: http://nodejs.org/docs/latest/api/events.html#events_emitter_setmaxlisteners_n

What version of Node is this? What other code do you have? That isn't normal behavior.

In short, its: process.setMaxListeners(0);

Also see: node.js - request - How to “emitter.setMaxListeners()”?

I'd like to point out here that that warning is there for a reason and there's a good chance the right fix is not increasing the limit but figuring out why you're adding so many listeners to the same event. Only increase the limit if you know why so many listeners are being added and are confident it's what you really want.

I found this page because I got this warning and in my case there was a bug in some code I was using that was turning the global object into an EventEmitter! I'd certainly advise against increasing the limit globally because you don't want these things to go unnoticed.

11 ready listeners added

means you have 11 <Discord.client>.on('ready', <function>)

so node.js warns you because that uses a lot of memory. You probably have nested events somewhere so it makes 11 ready events.

I resolved with this line:

process.setMaxListeners(Infinity);

Related