socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

"emitWithAck" function leaks memory when acknowledgement timeout

Open ZhangSen1 opened this issue 1 year ago • 2 comments

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.

ZhangSen1 avatar Mar 26 '24 06:03 ZhangSen1

Hi! I could indeed reproduce the issue, thanks for the detailed analysis :+1:

Not sure how we can fix this though, let me check.

darrachequesne avatar Mar 29 '24 09:03 darrachequesne

Any update on this @darrachequesne ?

We are experiencing this issue often too

maraujop avatar Oct 08 '24 09:10 maraujop