Skip to content

fix(sio-client): accept 0 for reconnectionAttempts, reconnectionDelay and reconnectionDelayMax - #5624

Open
mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/sio-client-zero-reconnection-options
Open

mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/sio-client-zero-reconnection-options

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

The constructor of the Manager reads reconnectionAttempts, reconnectionDelay and reconnectionDelayMax with ||, so the value 0 becomes the default value (Infinity, 1000 and 5000). Backoff does the same for min and max. The setters accept 0.

New behavior

The constructor and Backoff use ??, as randomizationFactor already does. The value 0 is kept. factor keeps ||: a factor of 0 gives no backoff.

Two tests are added in test/connection.ts: the getters and backoff.duration() return 0, and a Manager with reconnectionAttempts: 0 emits reconnect_failed and no reconnect_attempt.

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
== F0059 (fix/sio-client-zero-reconnection-options)
  commit 2ac6572e, base behind
  F0059-before:  0 passing (28ms)  2 failing  1) should accept 0 as the value of the reconnection options; 2) should not try to reconnect when requested zero attempts; 1) connection; 2) connection; exit=2
  F0059-after:  2 passing (14ms)  exit=0
  npm test:  117 passing (7s)  exit=0

The failures before the change:

  2 failing

  1) connection
       should accept 0 as the value of the reconnection options:
     Error: expected Infinity to equal 0
      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)

  2) connection
       should not try to reconnect when requested zero attempts:
     Error: should not happen
      at Manager.<anonymous> (test/connection.ts:432:14)

Other information (e.g. related issues)

Closes #5618

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

… and reconnectionDelayMax

The constructor of the Manager and the Backoff used "||", so the value 0
in the options was replaced by the default value (Infinity, 1000 and 5000),
while the setters accepted 0. With reconnectionAttempts: 0, the client
retried forever, and reconnect_failed was never emitted.

Related: socketio/socket.io-client#1231
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] reconnectionAttempts: 0 (and reconnectionDelay: 0, reconnectionDelayMax: 0) in the options become the default values

1 participant