Skip to content

"emitWithAck" function leaks memory when acknowledgement timeout #4984

@ZhangSen1

Description

@ZhangSen1

Describe the bug

When using "emitWithAck" on the server side, the memory is not freed when the acknowledgement timeout is reached.

I tested on 500 client connections, and the memory usage is 1557MB after 3 hours.

Steps:

  1. Connect 500 clients, 10 clients per room, 50 rooms
  2. The first client in each room sends a message to the room every second(use emitWithAck)
  3. Each client does not call callback after receiving a message(simulation timeout)
  4. Memory usage is not freed

To Reproduce

Socket.IO server version: 4.7.2

Server

try{
    const responses = await socket.timeout(2000).to("room1").emitWithAck("event", "message");
} catch(err){

}

Socket.IO client version: 4.7.2

Client

 socket.on("event", (data, callback) => {
      // Do not call callback, simulation timeout.
      // callback(1);
    });

Expected behavior

Should not leak memory

Platform:

  • Server Node.js version: 18.18.0
  • Client Node.js version: 18.18.0
  • OS: win 10

Additional context

See broadcast-operator.ts timer, it seems that when timeout, ack function is not deleted from socket.acks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    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