MaxListenersExceededWarning: Possible EventEmitter memory leak detected…

As I was working on my self-assigned homework to write an algorithm that would stream data in, and then hold the data in memory waiting for a rendezvous to happen, I ran into an error that was new to me:

MaxListenersExceededWarning: Possible EventEmitter memory leak detected

Some research pointed me to the root cause of my issue. You should only ever define a given event listener a single time. That means you shouldn’t define an event listener in a loop, or in a function (since the function sooner or latter will end up being called more than once).

I suspect it’s more of a rookie mistake, which means it’s a little embarrassing to admit to, but if I hide my deficiencies, it just makes it that much harder to get better. Besides, maybe someone else making that ‘rookie’ mistake will stumble onto this and it will help them debug their code a bit faster than they would have managed otherwise.

Leave a Reply