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

Memory leak

Open 3rd-Eden opened this issue 15 years ago • 10 comments

I have been outputting the internal data structure length and noticed the following:

(metric) server connections (132)
(metric) socket.io clients (576)
(metric) socket.io handshakes (598)
(metric) socket.io connected (576)
(metric) socket.io rooms (21)
(metric) socket.io roomClients (578)
(metric) socket.io open (119)
(metric) socket.io closed (1459)

There are way to much objects in our internal closed object. So something is not getting cleaned up properly.

3rd-Eden avatar Sep 10 '11 09:09 3rd-Eden

Node 0.4.8 Socket.IO server & client are 0.8.6

real connection count: ~30 | Open: 37, handshaken: 40, closed: 228, closedA: 1162 real connection count: ~80 | Open: 542, handshaken: 701, closed: 980, closedA: 969

the numbers are just so random at times...

seems like a very serious issue...

is it safe to loop over those objects (closed and closedA) every once in a while and delete all keys? - actually that doesnt free any memory anyways so its useless

what is closeA internally? will "client not handshaken client should reconnect" failed handshake IDs also end up there?

edit:

31 Oct 21:29:46 - Open: 102, handshaken: 121, closed: 1131, closedA: 13783 (~70 real connections)

edit:

Nov 13:06:41 - Open: 47, handshaken: 61, closed: 1489, closedA: 362424 <- after 10 hours of uptime, WTF?

thekiur avatar Oct 30 '11 16:10 thekiur

https://github.com/thekiur/socket.io/commit/9e92075cbb385d6037876c7cfedd8227f92b1a10

That was pulled to master so this issue is gone?

thekiur avatar Jan 05 '12 17:01 thekiur

@thekiur that only fixes one small part of it, the closed object is still leaking data.

3rd-Eden avatar Jan 05 '12 18:01 3rd-Eden

@thekiur a possible work around for this would be: https://github.com/observing/socket.io/commit/6d458d86697ddd8b10f68905fec02ca9feb3541c

Which doesn't solve the issue, but it does clean up the closed objects.

3rd-Eden avatar Jan 05 '12 18:01 3rd-Eden

Hey,

Do you use this on prod ? can i safe merge this to 8.7 ?

dymsza avatar Feb 24 '12 06:02 dymsza

This workaround is good, the mem stops leaking, but on production with many clients it eats all the cpu so in my case I just did cleaning the sockets on a timeout.

jdponomarev avatar Apr 01 '12 09:04 jdponomarev

How did you cleaned the sockets. i have the same problem the memory very big

guysaq avatar Jul 27 '12 15:07 guysaq

the same!~

zhangjf108 avatar Sep 15 '12 15:09 zhangjf108

Is problem solved?

itopenup avatar May 13 '13 22:05 itopenup

when client disconnect , transport should notify other server. i have change the transport , and maybe resolved it. https://github.com/wanghongxing/socket.io/commit/4ed630377681171948e4f7cedf91d07a95c36a57

wanghongxing avatar Jun 07 '13 07:06 wanghongxing