Skip to content

Commit ba9cd69

Browse files
revert: fix: cleanup pending acks on timeout to prevent memory leak
This reverts commit da04267. The reverted fix was incorrect because the rooms might have changed between the emit() and the timeout.
1 parent 84c2fb7 commit ba9cd69

File tree

4 files changed

+2
-21
lines changed

4 files changed

+2
-21
lines changed

packages/socket.io-adapter/lib/cluster-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ export abstract class ClusterAdapter extends Adapter {
508508
}, opts.flags!.timeout);
509509
}
510510

511-
return super.broadcastWithAck(packet, opts, clientCountCallback, ack);
511+
super.broadcastWithAck(packet, opts, clientCountCallback, ack);
512512
}
513513

514514
override async addSockets(opts: BroadcastOptions, rooms: Room[]) {

packages/socket.io-adapter/lib/in-memory-adapter.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,6 @@ export class Adapter extends EventEmitter {
229229
});
230230

231231
clientCountCallback(clientCount);
232-
233-
return {
234-
cleanup: () => {
235-
this.apply(opts, (socket) => {
236-
socket.acks.delete(packet.id);
237-
});
238-
},
239-
};
240232
}
241233

242234
private _encode(packet: unknown, packetOpts: Record<string, unknown>) {

packages/socket.io/lib/broadcast-operator.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,9 @@ export class BroadcastOperator<EmitEvents extends EventsMap, SocketData>
232232
const ack = data.pop() as (...args: any[]) => void;
233233
let timedOut = false;
234234
let responses: any[] = [];
235-
let cleanupPendingAcks: (() => void) | undefined;
236235

237236
const timer = setTimeout(() => {
238237
timedOut = true;
239-
cleanupPendingAcks?.();
240238
ack.apply(this, [
241239
new Error("operation has timed out"),
242240
this.flags.expectSingleResponse ? null : responses,
@@ -261,7 +259,7 @@ export class BroadcastOperator<EmitEvents extends EventsMap, SocketData>
261259
}
262260
};
263261

264-
const result = this.adapter.broadcastWithAck(
262+
this.adapter.broadcastWithAck(
265263
packet,
266264
{
267265
rooms: this.rooms,
@@ -281,10 +279,6 @@ export class BroadcastOperator<EmitEvents extends EventsMap, SocketData>
281279
},
282280
);
283281

284-
if (result && typeof result.cleanup === "function") {
285-
cleanupPendingAcks = result.cleanup;
286-
}
287-
288282
this.adapter.serverCount().then((serverCount) => {
289283
expectedServerCount = serverCount;
290284
checkCompleteness();

packages/socket.io/test/messaging-many.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,6 @@ describe("messaging many", () => {
534534
// @ts-ignore
535535
expect(err.responses).to.contain(1, 2);
536536

537-
for (const [, serverSocket] of io.of("/").sockets) {
538-
// @ts-ignore accessing private acks map to verify cleanup
539-
expect(serverSocket.acks.size).to.be(0);
540-
}
541-
542537
success(done, io, socket1, socket2, socket3);
543538
}
544539
});

0 commit comments

Comments
 (0)