Skip to content

Memory leak with rooms #1736

@Morthy

Description

@Morthy

We've been running into a memory leak problem in a production environment where socket.io receives a very large amount of new connections/disconnections in a relatively small amount of time.

It would appear that the automatic room that is created for a new socket is never deleted when the socket disconnected. We tested this by stripping out all of our logic and benchmarking against a simple socket.io instance, with no authentication logic, custom rooms, or even emitting any messages. Every 2 seconds we outputted the memory usage, connected sockets. and number of rooms:

Memory used: 14444584 - Connected sockets: 41 - Rooms: 56
Memory used: 15919872 - Connected sockets: 133 - Rooms: 159
Memory used: 23399352 - Connected sockets: 225 - Rooms: 251
Memory used: 31132280 - Connected sockets: 315 - Rooms: 344
Memory used: 34205984 - Connected sockets: 395 - Rooms: 436
Memory used: 29165872 - Connected sockets: 472 - Rooms: 527
Memory used: 29414112 - Connected sockets: 539 - Rooms: 620
Memory used: 38353000 - Connected sockets: 210 - Rooms: 652
Memory used: 41053952 - Connected sockets: 1 - Rooms: 652
Memory used: 41071808 - Connected sockets: 1 - Rooms: 652

We determined the number of rooms using:

Object.keys(io.sockets.adapter.rooms).length;

To confirm this, we created a memory dump before and after the connections and compared them using Chrome's dev tools. As you can see, there are many rooms remaining, even though no connections remained: http://i.imgur.com/wuftdnH.png

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions