Skip to content

fix(sio-client): remove the ack handler of a discarded volatile packet - #5622

Open
mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/sio-client-volatile-ack-leak
Open

mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/sio-client-volatile-ack-leak

Conversation

@mark1russell7

@mark1russell7 mark1russell7 commented Nov 14, 2026 •

Copy link
Copy Markdown

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behavior

emit() registers the ack handler before it decides to discard a volatile packet, and nothing removes the handler when the packet is discarded. The server never acknowledges the packet, so the handler stays in socket.acks, emitWithAck() never settles, and the callback of timeout() gets an error only when the timer ends.

New behavior

The client removes the handler when it discards the packet. As in _clearAcks(), a handler that takes an error as first argument (with timeout(), or emitWithAck()) is called at once with an error ("packet has been discarded").

Three tests are added in test/socket.ts: a callback, a callback with timeout(), and emitWithAck().

The tests ran in GitHub Actions (Node.js 24.22.2 on Linux): the new tests with the lib folder of upstream main (before), then with this change (after), then npm test of socket.io-client with this change:

upstream main: 545e9848500d6133c9a1cdb6fee87009d0150f9c
== F0056 (fix/sio-client-volatile-ack-leak)
  commit 1c55bfa4, base current
  F0056-before:  0 passing (4s)  3 failing  1) should not keep the ack handler of a discarded volatile packet (callback); 2) should ack with an error when a volatile packet is discarded (callback & timeout); 3) should reject when a volatile packet is discarded (promise); 1) socket; 2) socket; exit=3
  F0056-after:  3 passing (10ms)  exit=0
  npm test:  118 passing (8s)  exit=0

The failures before the change:

  3 failing

  1) socket
       volatile packets
         should not keep the ack handler of a discarded volatile packet (callback):

      Error: expected 1 to sort of equal 0
      + expected - actual

      -1
      +0
      
      at Assertion.assert (/home/runner/work/wirelab/wirelab/repros/fix-tests/socket.io-client/group-1/socket.io/node_modules/expect.js/index.js:96:13)

  2) socket
       volatile packets
         should ack with an error when a volatile packet is discarded (callback & timeout):
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/runner/work/wirelab/wirelab/repros/fix-tests/socket.io-client/group-1/socket.io/packages/socket.io-client/test/socket.ts)
      at listOnTimeout (node:internal/timers:685:17)

  3) socket
       volatile packets
         should reject when a volatile packet is discarded (promise):
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/runner/work/wirelab/wirelab/repros/fix-tests/socket.io-client/group-1/socket.io/packages/socket.io-client/test/socket.ts)
      at listOnTimeout (node:internal/timers:685:17)

Other information (e.g. related issues)

Closes #5615

This PR and #5621 add tests at the same place in test/socket.ts. When one is merged, I will update the other.

This PR was prepared with AI assistance (Claude). The tests above were run before and after the change, with the results above.

🤖 Generated with Claude Code

The ack handler was registered before the volatile packet was discarded,
and it was never removed: the handler leaked, and emitWithAck() never
settled.

Now the handler is removed once the packet is discarded. As in
_clearAcks(), a handler that accepts an error as first argument (with a
timeout, or emitWithAck()) is called with an error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[socket.io-client] A discarded volatile packet keeps its ack handler: the handler leaks, and emitWithAck() never settles

1 participant