socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Socket not cleanly closed when use cluster and socket.io with RedisStore

Open RavenZZ opened this issue 12 years ago • 7 comments

When I use cluster and RedisStore ,then always there are 10% socket connected all the time , I judget it by var sock = io.sockets.sockets[sid]; if (sock != undefined && sock.disconnected == false) { //connected }else{ //disconnected } Yesterday, I ran application in single process(without cluster) ,all of sockets closed;

RavenZZ avatar Feb 11 '14 01:02 RavenZZ

Hi i'm having similar issue with RedisStore, may be we can help each other. Check out this links: https://github.com/LearnBoost/socket.io/issues/831 https://github.com/SpiderStrategies/socket.io/commit/caa96a5cc207aaff23db94a03a2412f5a8c8a4f6 https://github.com/observing/socket.io/commit/6d458d86697ddd8b10f68905fec02ca9feb3541c

nicoburghi avatar Feb 14 '14 20:02 nicoburghi

Can you tell where did you add the piece of code? did you fix something with it or was just for checking? Thanks

nicoburghi avatar Feb 14 '14 20:02 nicoburghi

I store all socket id in my db , when I found that some socket didn't clear , I tried to clear them in the same process. but it doesn't works. sorry,I still doesn't fix it :( ; I will try your method and tell you whether it works ^_^

RavenZZ avatar Feb 15 '14 15:02 RavenZZ

great, that links help me to fix part of the issue, I still have some references to Socket objects that must be deleted. On monday i will work hard with de socket.io garbage collector (in manager.js) to look for a fix. My worst problem is that after some days of the servers running i run out of memory, so this issue is causing memory leaks. I hope we can fix this :)

nicoburghi avatar Feb 15 '14 16:02 nicoburghi

Your method seems doesn't work on my application . and I got the memory issue today...

RavenZZ avatar Feb 20 '14 06:02 RavenZZ

That's bad, can you find out the number of opened sockets when the leaks happen? I'm now trying to do some test cases in order to find a fix. I'll see how the memory behaves these days and tell you.

I'm ising this to list my socket objects. Maybe you find it useful

app.get("/socketInfo", function(req, res){ var numberOfSockets = Object.keys(socketIO.connected).length; var socketIds = socketIO.rooms[''] ? socketIO.rooms[''] : []; var data = { numberOfSockets: numberOfSockets, socketIds: socketIds, connected: socketIO.connected, open: socketIO.open, closed: socketIO.closed, rooms: socketIO.rooms, roomClients: socketIO.roomClients, handshaken: socketIO.handshaken }; res.json(data); });

nicoburghi avatar Feb 20 '14 20:02 nicoburghi

about 100-300 socket connections

RavenZZ avatar Feb 26 '14 02:02 RavenZZ