Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socket.io redis and memory leak

My socket.io version is [email protected] and [email protected]. I am on Windows.

In some places, I have seen that the issue is solved. I suppose I am using the latest socket.io version. what is emitter.setMaxListeners() and where can I set it ?

(node) warning: possible EventEmitter memory leak detected. 11 listeners added.
Use emitter.setMaxListeners() to increase limit.
Trace:
    at RedisClient.<anonymous> (events.js:133:17)
    at Socket.<anonymous> (c:\HTML5\LIKEPREF\test\server\server.js:576:18)
    at Socket.$emit (events.js:67:17)
    at SocketNamespace.handlePacket (C:\Personal\software\nodejs\NODE\node_modul
es\socket.io\lib\namespace.js:335:22)
    at Manager.onClientMessage (C:\Personal\software\nodejs\NODE\node_modules\so
cket.io\lib\manager.js:459:38)
    at WebSocket.onMessage (C:\Personal\software\nodejs\NODE\node_modules\socket
.io\lib\transport.js:387:20)
    at Parser.<anonymous> (C:\Personal\software\nodejs\NODE\node_modules\socket.
io\lib\transports\websocket\hybi-16.js:40:10)
    at Parser.emit (events.js:67:17)
    at C:\Personal\software\nodejs\NODE\node_modules\socket.io\lib\transports\we
bsocket\hybi-16.js:286:16
    at Parser.expectHandler (C:\Personal\software\nodejs\NODE\node_modules\socke
t.io\lib\transports\websocket\hybi-16.js:297:15)

I am using redis pubsub and when i am subscribing to redis, at that point it throws up this warning.

like image 232
user644745 Avatar asked Jan 18 '23 11:01

user644745


1 Answers

There is a known issue associated with this. Looks like it was patched several months ago. The easiest fix is to set the maximum listeners to 0 which will remove the actual limit. So it would look something like this:

this.sub = redis.createClient(opts.redisSub.port, opts.redisSub.host, opts.redisSub);
this.sub.setMaxListeners(0);

You can find the full discussion here: https://github.com/LearnBoost/socket.io/issues/520

like image 147
Swift Avatar answered Jan 26 '23 00:01

Swift