fix: tweak keep-alive timeout implementation#3145
Merged
Merged
Conversation
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.
Closes #3141
This relates to...
Rationale
The goal of the util/timers.js is to provide setTimeout-compatible timers with 1 second granularity, as opposed to native setTimeout's 1ms. Because the timers were scheduled, then executed in two separate "ticks" of the fast timeout, this meant timeouts are called best case 1000ms after intended, and worst case 2000ms. Combined with the previous 1000ms default for
keepAliveTimeoutThreshold, the end result is an effective keepAliveTimeoutThreshold of 0 -- so unluckily timed requests would attempt to use a connection which has already been closed by the remote.Changes
Multi-pronged approach here to prioritize safety and avoid attempting to re-use sockets that have already been closed:
Note to @ronag I went with change 2 instead of the proposed subtraction of the tick time from the duration because after writing the tests, that approach was more flaky.
Features
N/A
Bug Fixes
Some of the reports in #3133 may be resolved by this change, though it would need to be backported to 5.x, included in a Node v20 release, and then picked up by Amazon before we would see any improvement. ¯\_(ツ)_/¯
Breaking Changes and Deprecations
The more conservative default keepAliveTimeoutThreshold value should not be a breaking change.
Benchmarks
Within run-to-run variance:
PR:
main:Status