Skip to content

fix(eio-client): clamp the delay of the heartbeat timer - #5609

Open
mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/eio-client-heartbeat-timer-overflow
Open

mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/eio-client-heartbeat-timer-overflow

Conversation

@mark1russell7

@mark1russell7 mark1russell7 commented Nov 13, 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

_resetPingTimeout() creates the heartbeat timer with a delay of pingInterval + pingTimeout. When the sum is above 2^31 - 1 ms (about 24.8 days), setTimeout() fires almost at once, so the client closes the connection with the reason ping timeout right after the handshake. The server accepts these values, since each of its timers uses only one of them.

New behavior

The delay is limited to 2^31 - 1 ms, the maximum delay of setTimeout(). _pingTimeoutTime, which _hasPingExpired() uses, gets the same delay. Each ping of the server resets the timer as before, so the limit only has an effect when the server sends no ping for about 24.8 days.

Other information (e.g. related issues)

Fixes #5608

The new test in test/node.js ("should not close when pingInterval + pingTimeout is above the maximum timer delay") starts an engine.io server with pingInterval: 25000 and pingTimeout: 2147483647, and checks that the socket is still open 100 ms after the open event.

Test results (Node.js 24.21.0, Windows 11, in packages/engine.io-client after npm run compile):

  • mocha --exit --require test/support/hooks.js --require test/support/env.js test/node.js
    • without the change of lib/: 21 passing, 1 failing: the new test fails with expected 'closed' to sort of equal 'open'
    • with the change: 22 passing
  • mocha --exit --require test/support/hooks.js test/index.js (the Node.js suite, without test/webtransport.mjs): 99 passing, 1 pending; with USE_FETCH=1: 98 passing, 2 pending
  • prettier --check of the changed files: no problems

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

🤖 Generated with Claude Code

The heartbeat timer was created with a delay of pingInterval +
pingTimeout. When the sum was above 2^31 - 1 ms (about 24.8 days),
setTimeout() fired immediately, so the client closed the connection
with the "ping timeout" reason right after the handshake. The server
accepts these values, since each of its timers uses only one of them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

[engine.io-client] The client closes with "ping timeout" right after the handshake when pingInterval + pingTimeout is above 2^31 - 1 ms

1 participant