Skip to content

fix(sio-client): discard a volatile packet when the namespace is not connected - #5621

Open
mark1russell7 wants to merge 2 commits into
socketio:mainfrom
mark1russell7:fix/sio-client-volatile-not-connected
Open

mark1russell7 wants to merge 2 commits into
socketio:mainfrom
mark1russell7:fix/sio-client-volatile-not-connected

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

A volatile packet is discarded only when the transport is not writable. When the transport is writable and the socket is not connected yet (the handshake of a namespace on a connected Manager, or after a reconnection), the packet goes into sendBuffer and the client sends it after the connect event.

The documentation of the volatile flag says that the event "will be dropped when this socket is not ready to send messages".

New behavior

The client discards a volatile packet when the transport is not writable or the socket is not connected.

A test is added in test/socket.ts ("should discard a volatile packet when the namespace is not connected yet"). It uses a new namespace /delayed in test/support/server.ts, whose middleware answers after 100 ms. The test checks that the transport is writable and the socket is not connected before it emits.

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
== F0055 (fix/sio-client-volatile-not-connected)
  commit d4804fdd, base current
  F0055-before:  0 passing (149ms)  1 failing  1) should discard a volatile packet when the namespace is not connected yet; 1) socket; exit=1
  F0055-after:  1 passing (144ms)  exit=0
  npm test:  116 passing (8s)  exit=0

The failures before the change:

  1 failing

  1) socket
       volatile packets
         should discard a volatile packet when the namespace is not connected yet:
     Error: should not happen
      at Socket.<anonymous> (test/socket.ts:441:20)

Other information (e.g. related issues)

Closes #5614

This PR and #5622 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

…connected

A volatile packet was discarded only when the transport was not writable.
During the handshake of a namespace (for example a second namespace on a
connected Manager, or right after a reconnection), the transport is
writable but the socket is not connected yet, so the packet was buffered
and sent once connected.

The documentation of the volatile flag says the event "will be dropped
when this socket is not ready to send messages".
…able again

Right after the CONNECT packet of the namespace, the transport is not
writable, so the volatile packet was discarded even without the fix. The
test now uses a namespace that delays its acknowledgement, and emits the
packet once the transport is writable again.
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 volatile event emitted before the namespace is connected is sent later, not dropped

1 participant