fix(transport-webrtc): fix EOF race in readCandidatesUntilConnected#3460
Open
paschal533 wants to merge 2 commits intolibp2p:mainfrom
Open
fix(transport-webrtc): fix EOF race in readCandidatesUntilConnected#3460paschal533 wants to merge 2 commits intolibp2p:mainfrom
paschal533 wants to merge 2 commits intolibp2p:mainfrom
Conversation
…ntilConnected A race condition caused intermittent failures in the WebRTC 'simple' transport compliance test: the listener closes its signaling stream just before the initiator's connectionstatechange fires for the 'connected' state. The initiator then receives EOF on the signaling stream and threw an UnexpectedEOFError, discarding a perfectly good peer connection. Root cause: connectedPromise was declared inside the try block, making it inaccessible in the catch handler for stream read errors. Fix: move connectedPromise outside the try block. In the catch handler, if the PC is not yet 'connected', await connectedPromise — if it resolves we ignore the stream error (the connection succeeded); if it rejects we re-throw the original stream error.
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.
Problem
A race condition caused the WebRTC "simple" transport compliance test to fail intermittently: the listener closes its signaling stream just before the initiator's
connectionstatechange: connectedevent fires. The initiator then received EOF on the signaling stream and threw anUnexpectedEOFError, discarding a perfectly good peer connection.Root cause:
connectedPromisewas declared inside thetryblock, making it inaccessible in thecatchhandler for stream read errors.Solution
Move
connectedPromiseoutside thetryblock. In thecatchhandler, if the peer connection is not yet'connected', awaitconnectedPromise:Also corrects the log message from "error parsing ICE candidate" to "error reading ICE candidates" for accuracy.
Test plan
readCandidatesUntilConnecteddescribe block with 4 testsConnectionFailedErrorwhen the peer connection enters'failed'stateConnectionFailedErrorwhen peer connection goes disconnected then failed'connected'stateRelated PRs
This is one of four focused fixes split from #3406 as requested by @dozyio:
UnexpectedEOFErrorrace inreadCandidatesUntilConnected'disconnected'as a terminal peer connection state