Skip to content

Memory leak - adapter.rooms.size getting bigger and bigger #4067

Closed
@BlackBacker

Description

@BlackBacker

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 on 2.2.0)

Server

import io from 'socket.io';
import express from 'express';

const app = express();
const server =  app.listen(3000);
io(server, {});
userNamespace = socketIo.of('/');

let disconnectCount = 0;

userNamespace.on('connection', async (socket) => {
 const roomId = Math.round(Math.random() * 10000000000);
  socket.join(`Room - ${roomId}`);

  socket.on('disconnect', () => {   // SECOND BUG - not called every time when connection is closed
    disconnectCount++;
    //console.log('Room - ${roomId} - leave'); 
  });
});


setInterval(() => {
  console.log(`Room size ${userNamespace.adapter.rooms.size}, disconnect count ${disconnectCount}`);
}, 5000);

WS client

Client for server v.4.1.3

npm install -g artillery@latest
npm install artillery-engine-socketio-v3

400 connections (rooms)
test.yaml

config:
  target: "http://localhost:3000/"
  phases:
  - duration: 10
    arrivalRate: 40
  engines:
    socketio-v3: {}
scenarios:
- name: "A user that just lurks"
  weight: 90
  engine: "socketio-v3"
  flow:
  - emit: ["add user"]
  - think: 1

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:

(output only for - FIRST RUN)
Summary report @ 15:31:25(+0200) 2021-08-30
  Scenarios launched:  400
  Scenarios completed: 395
  Requests completed:  395
  Mean response/sec: 31.63
  Response time (msec):
    min: 0.2
    max: 3.8
    median: 0.3
    p95: 0.6
    p99: 1.6
  Scenario counts:
    A user that just lurks: 400 (100%)
  Codes:
    0: 395
  Errors:
    Error: xhr poll error: 5
// FIRST RUN (0 >> 38) - should be zero at the end
  Codes:
    0: 395
  Errors:
    Error: xhr poll error: 5

Room size 0
Room size 6
Room size 76
Room size 178
Room size 32
Room size 74
Room size 74
Room size 74
Room size 74
Room size 46
Room size 38
// SECOND RUN (38 >> 76)
  Codes:
    0: 400
  Errors:
    -

Room size 38
Room size 96
Room size 140
Room size 123
Room size 76
// THIRD RUN (74 >> 292)
  Codes:
    0: 379
  Errors:
    Error: xhr poll error: 21


Room size 74
Room size 98
Room size 156
Room size 264
Room size 217
Room size 292
Room size 292
Room size 292

Expected behavior
Room size should be 0 at the end of tests, after close all connections.

Platform:

  • Device: Chrome
  • OS: Windows
  • Socket.io 4.1.3 (also tried on 2.2.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions