"emitWithAck" function leaks memory when acknowledgement timeout
Nobody has claimed this yet.
- 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:
- Connect 500 clients, 10 clients per room, 50 rooms
- The first client in each room sends a message to the room every second(use emitWithAck)
- Each client does not call callback after receiving a message(simulation timeout)
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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