Empty rooms aren't deleted
See original GitHub issueI noticed a possible memory leak, so I tested by connecting to my server from about a dozen client webpages and repeatedly refreshing them. Memory usage increased with each refresh and never fell back to pre-refresh levels.
Turns out the unique rooms that are created for new connections aren’t getting deleted — they remain in the room list despite becoming empty upon refresh. Empty rooms are supposed to be destroyed automatically, so I don’t know what’s going on, but it might be why memory usage keeps rising.
I tried explicitly deleting these rooms when a client disconnects. This removes them from the room list, but memory usage seems unaffected. I might be doing it wrong:
socket.on('disconnect', function() {
delete io.sockets.adapter.rooms[socket.id];
});
Does this seem strange to anyone else? Is there another potential reason for the memory leak?
Issue Analytics
- State:
- Created 9 years ago
- Comments:22 (9 by maintainers)
Top GitHub Comments
I see this has been closed, but it does not appear to be resolved. Can we get some sort of comment on this please?
Will manually doing
socket.join(<room string>)
not auto delete a room upon disconnect?
Does this demand manual deletion? I’m seeing in my logs of a rather basic chat server that huge stacks of rooms are being kept in even after disconnection (force OR clean disconnect).
@ncacace I think your use case is a bit too specific to be implemented in socket.io internals.
The room is destroyed once the last element leaves it (https://github.com/socketio/socket.io-adapter/blob/1.1.1/index.js#L81).