Repository navigation
fix(eio-client): clamp the delay of the heartbeat timer - #5609
Open
mark1russell7 wants to merge 1 commit into
Open
mark1russell7 wants to merge 1 commit into
mark1russell7 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The kind of change this PR does introduce
Current behavior
_resetPingTimeout()creates the heartbeat timer with a delay ofpingInterval + 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 reasonping timeoutright 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 withpingInterval: 25000andpingTimeout: 2147483647, and checks that the socket is still open 100 ms after theopenevent.Test results (Node.js 24.21.0, Windows 11, in
packages/engine.io-clientafternpm run compile):mocha --exit --require test/support/hooks.js --require test/support/env.js test/node.jslib/: 21 passing, 1 failing: the new test fails withexpected 'closed' to sort of equal 'open'mocha --exit --require test/support/hooks.js test/index.js(the Node.js suite, withouttest/webtransport.mjs): 99 passing, 1 pending; withUSE_FETCH=1: 98 passing, 2 pendingprettier --checkof the changed files: no problemsThis 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