socket.io
socket.io copied to clipboard
memory leak
socket.io version:^4.5.1
memory keep increasing and no reduce, it seems that every connection will never be released,unconnected socket will stay in memory will never be released
this is my main socket.io code: chat.js.zip
this is dump file socket.io server at start: 1660347155092.heapsnapshot.zip
this is dump file socket.io server after about 12 hours: 1660434926431.heapsnapshot.zip
nodejs log
nodejs exists a lot of unrecyler connection,actually socket server has at most 50 connections at one time,but memory show 1000+connections.

this is memory record at start: { gc_ts: 1660435083534346, gcScavengeCount: 6, gcScavengeTime: 35094684, gcMarkSweepCompactCount: 1, gcMarkSweepCompactTime: 11370196, gcIncrementalMarkingCount: 2, gcIncrementalMarkingTime: 779792, gcProcessWeakCallbacksCount: 1, gcProcessWeakCallbacksTime: 229, total_heap_size: 109916160, total_heap_size_executable: 2359296, total_physical_size: 109668288, total_available_size: 2089975504, used_heap_size: 82783856, heap_size_limit: 2197815296, malloced_memory: 1065032, peak_malloced_memory: 3763256, gc_time: 11370196 }
this is memory record after about 12 hours: { gc_ts: 1660434978708896, gcScavengeCount: 8330, gcScavengeTime: 6094003772, gcMarkSweepCompactCount: 68, gcMarkSweepCompactTime: 1072605909, gcIncrementalMarkingCount: 132, gcIncrementalMarkingTime: 61912948, gcProcessWeakCallbacksCount: 2, gcProcessWeakCallbacksTime: 4448, total_heap_size: 114634752, total_heap_size_executable: 5767168, total_physical_size: 113205152, total_available_size: 2085620912, used_heap_size: 109306480, heap_size_limit: 2197815296, malloced_memory: 4210760, peak_malloced_memory: 4870952, gc_time: 36112984 }
unrelated but you've got some overlapping variable names. probably would help to organize and refactor a bit.
I also got a memory leak in a Socket.IO game.
Before (when I start the server):
After (when I connect and play for a while):
I download the chat.js.zip
, oh my god, so many leak possible change in the code...
I download the
chat.js.zip
, oh my god, so many leak possible change in the code...
please tell me many leak possible code ? thanks a lot
try 4.5.2
Another suggest, if you write node.js, typescript is a good choice, strong type.
@leviluo your js code is messy
Another suggest, if you write node.js, typescript is a good choice, strong type.
thanks a lot,i have try 4.5.2,but it still memory leak, in next day i will try typescript.
@leviluo could you please provide a minimal example reproducing the issue? I think the memory leak that you are experiencing comes from somewhere in your code, not Socket.IO.
See also: https://socket.io/docs/v4/memory-usage/
I'm going to close this, as the memory leaks does not seem to come from Socket.IO itself. Please reopen if needed.