Skip to content

fix(sio-client): set recovered to false when the server does not use connection state recovery - #5625

Open
mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/sio-client-recovered-boolean
Open

mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/sio-client-recovered-boolean

Conversation

@mark1russell7

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

onconnect() sets this.recovered = pid && this._pid === pid. When the server does not use connection state recovery, pid is undefined, so socket.recovered becomes undefined, although its type is boolean.

New behavior

this.recovered = !!pid && this._pid === pid, so the value is always a boolean.

A test is added in test/connection-state-recovery.ts ("should not be recovered when the server does not use connection state recovery").

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: f97d51a810d4f266122eb99bb6c083cd383638f0
== F0060 (fix/sio-client-recovered-boolean)
  commit ecff3ffc, base behind
  F0060-before:  0 passing (7ms)  1 failing  1) should not be recovered when the server does not use connection state recovery; 1) connection state recovery; exit=1
  F0060-after:  1 passing (4ms)  exit=0
  npm test:  116 passing (7s)  exit=0

The failures before the change:

  1 failing

  1) connection state recovery
       should not be recovered when the server does not use connection state recovery:
     Error: expected undefined to equal false
      at Assertion.assert (/home/runner/work/wirelab/wirelab/repros/fix-tests/socket.io-client/group-2/socket.io/node_modules/expect.js/index.js:96:13)

Other information (e.g. related issues)

Closes #5619

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

…connection state recovery

Without connection state recovery, the CONNECT packet of the server has
no "pid" attribute, so socket.recovered was undefined instead of false,
although its type is boolean.
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] socket.recovered is undefined, not false, when the server does not use connection state recovery

1 participant