fix(transport): add timeout to closeAndWait to prevent hangs#40750
Closed
SebTardif wants to merge 3 commits into
Closed
fix(transport): add timeout to closeAndWait to prevent hangs#40750SebTardif wants to merge 3 commits into
SebTardif wants to merge 3 commits into
Conversation
closeAndWait awaits the WebSocket close event with no deadline. If the remote end never sends a close frame, the caller hangs indefinitely. Add a 30-second timeout via Promise.race so the close path always completes. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Clear the setTimeout timer after Promise.race resolves to avoid keeping the event loop alive unnecessarily. Also remove the parameter to keep the public signature unchanged. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Member
|
Let's add a test that demonstrates the issue (fails w/o the fix). |
Add two tests demonstrating the fix: - closeAndWait completes within timeout when server never sends close - closeAndWait returns immediately when already closed Re-add timeoutMs parameter (default 30s) so tests can use a short timeout without waiting 30 seconds. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Contributor
Author
|
Added two tests in
Re-added the |
Member
|
These pass for me w/o the fix. |
Contributor
Author
|
You're right, the |
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.
Summary
closeAndWaitawaits the WebSocket close event with no deadline; if the remote end never sends a close frame, the caller hangs indefinitelyPromise.raceso the close path always completesFailure scenario: Called in the error cleanup path of
WebSocketTransport._connect()(line 128). If the initial connection fails but the WebSocket never emits a close event (e.g., network partition, unresponsive remote),closeAndWaitblocks forever, preventing the connection error from propagating to the caller.Origin:
closeAndWaitwas introduced in #2350 (2020-05-29) by Dmitry Gozman as part of the Progress concept.