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

memory leak

Open leviluo opened this issue 2 years ago • 8 comments

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 截屏2022-08-15 14 18 34 屏幕截图 2022-09-12 074103

nodejs exists a lot of unrecyler connection,actually socket server has at most 50 connections at one time,but memory show 1000+connections. 截屏2022-08-22 15 53 23

截屏2022-08-17 20 10 06

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 }

leviluo avatar Aug 14 '22 01:08 leviluo

unrelated but you've got some overlapping variable names. probably would help to organize and refactor a bit.

dhenson02 avatar Aug 14 '22 04:08 dhenson02

I also got a memory leak in a Socket.IO game.

Before (when I start the server): image

After (when I connect and play for a while): image

lafkpages avatar Aug 26 '22 17:08 lafkpages

I download the chat.js.zip, oh my god, so many leak possible change in the code...

jiouiuw avatar Sep 04 '22 07:09 jiouiuw

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

leviluo avatar Sep 08 '22 01:09 leviluo

try 4.5.2

jiouiuw avatar Sep 08 '22 02:09 jiouiuw

Another suggest, if you write node.js, typescript is a good choice, strong type.

jiouiuw avatar Sep 08 '22 02:09 jiouiuw

@leviluo your js code is messy

jiouiuw avatar Sep 08 '22 02:09 jiouiuw

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 avatar Sep 12 '22 09:09 leviluo

@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/

darrachequesne avatar Dec 09 '22 07:12 darrachequesne

I'm going to close this, as the memory leaks does not seem to come from Socket.IO itself. Please reopen if needed.

darrachequesne avatar Jan 09 '23 08:01 darrachequesne