yeahoffline / redis-mock

Node.js redis client mock
212 stars 110 forks source link

MaxListenersExceededWarning: Possible EventEmitter memory leak detected #181

Open fabiansperber opened 3 years ago

fabiansperber commented 3 years ago

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 commented 3 years ago

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

baflo commented 3 years ago

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 commented 3 years ago

And quitting the client does not help, either:

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

Any update on this?

arovetto commented 1 year ago

Any update?