redis-mock icon indicating copy to clipboard operation
redis-mock copied to clipboard

MaxListenersExceededWarning: Possible EventEmitter memory leak detected

Open fabiansperber opened this issue 4 years ago • 5 comments

In class RedisClient this._redisMock.on('message', (ch, msg) => this._message(ch, msg)); the callback needs to be stored and used for removeListener later in quit(). Right now you are trying to remove a different listener (which wasn't registered) as these are two separate anonymous functions

fabiansperber avatar Feb 25 '21 08:02 fabiansperber

Ok, nevermind?! I had a leak of the client in one of my tests. It seems to work now. Still I believe one would need to store the anonymous arrow function for later removal, but I don't understand why it work nevertheless.. You may just close this if it's a non-issue

fabiansperber avatar Feb 25 '21 08:02 fabiansperber

I have the same problem. I searched for places where the client would leak, but was successful :/

This snippet is enough to trigger the error message:

Array.from({ length: 11 }).forEach(() => require("redis-mock").createClient())

// (node:7720) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added to [RedisMock]. Use emitter.setMaxListeners() to increase limit

baflo avatar Apr 21 '21 10:04 baflo

And quitting the client does not help, either:

Array.from({ length: 11 }).forEach(() => require("redis-mock").createClient().quit());

baflo avatar Apr 21 '21 10:04 baflo

Any update on this?

khoirulamri avatar Jan 13 '22 12:01 khoirulamri

Any update?

arovetto avatar Feb 08 '23 17:02 arovetto