socketio / socketio/socket.io

"emitWithAck" function leaks memory when acknowledgement timeout

Open
#4,984 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
63.2k
Forks
10.3k
Avg merge
11d 20h
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the timeout timer in lib/broadcast-operator.ts and the acknowledgement handling in socket.io-adapter's lib/in-memory-adapter.ts. Reproduce the 500-client scenario with emitWithAck and clients that do not acknowledge, then verify that memory is released after the timeout.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.