-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak - adapter.rooms.size getting bigger and bigger #4067
Comments
I think what you are seeing is clients that establish an HTTP long-polling connection, and then get killed. The server should properly remove them when the heartbeat fails. The room size should return to 0 after a delay (by default, 45 seconds, which is Documentation: https://socket.io/docs/v4/server-initialization/#pingTimeout You can also try be manually creating the clients: https://socket.io/docs/v4/load-testing/#Manual-client-creation |
I agree, but it's not happening, even after 10 minutes the room size is still the same.. (default settings - socket.io 4.2.0) userNamespace.adapter.rooms.size
userNamespace.adapter.sids.size are same size. It works perfectly normal when there is no pressure on the server (100 conn), for example with setting:
the output is:
but with more connections (400)
the output is (from artillery):
So there should be Room size 0, disconnect count 367, but the output is (after few minutes):
|
I want to add a question related to disconnection and memory leaks. Socket.io removes the listener after detecting the disconnection? Or need to manually call |
@matiaslopezd the You can test it by creating a lot of clients and check the heapdump after disconnection: https://socket.io/docs/v4/load-testing/ @BlackBacker apart from getting a warning from artillery, I can't reproduce:
In your case, maybe artillery is spawning some kind of zombie clients? Could you please check the size of the |
My application is proprietary but I can confirm this is happening also. Over 12 hours I'm logging 27k connections and 24k disconnections. It's eventually causing my application to crash |
@JustAnotherSoftwareDeveloper could you please provide a heap dump? Or anything that could help us find the culprit? |
Calling `socket.join()` after disconnection would lead to a memory leak, because the room was never removed from the memory: ```js io.on("connection", (socket) => { socket.disconnect(); socket.join("room1"); // leak }); ``` Related: - socketio#4067 - socketio#4380
Describe the bug
Room size is getting bigger while there are a lot of connections.
I think problem is more obvious, when server is not able to handle connections - if there is a lot of connections in the same time
Second issue is with disconnect event - not called every time when connection is closed/killed (don't know if it's bug)
To Reproduce
Just copy&paste&run the code under.
Socket.IO server version:
4.1.3
(also tried on2.2.0
)Server
WS client
Client for server v.4.1.3
400 connections (rooms)
test.yaml
Run client
artillery run test.yaml
Important is return codes - 395x of "0" which is OK. 5x unable to connect. Client output should be something like this:
Expected behavior
Room size should be 0 at the end of tests, after close all connections.
Platform:
The text was updated successfully, but these errors were encountered: