e2e: fix teardown race in webdartc-closes-data-channel test#44
Merged
Conversation
The Scenario 1 close test flaked on Linux CI (waitFor dcClosed timed out after 10s). Root cause: the offerer helper closes the PeerConnection immediately after its own DataChannel.onClose. Closing a data channel is a bidirectional SCTP stream reset (RFC 8831 §6.7): webdartc sends an Outgoing SSN Reset Request, Chrome answers with a Re-config Response (which completes webdartc's reset → our onClose fires) AND sends its own reciprocal Outgoing reset request. Chrome only fires its onclose once we answer that reciprocal request. The CI log's last inbound chunk was Chrome's Response alone (0x82 / param 0x0010 / result=1) — its reciprocal request hadn't arrived yet when our onClose fired and the helper tore the transport down, so Chrome's request landed on a dead connection and Chrome's onclose (the test's dcClosed) never came. Keep the PeerConnection alive ~2s after our onClose (only on the close path) so the SCTP stack can answer Chrome's reciprocal reset and the bidirectional close completes. This is a helper-only fix — real apps keep the PeerConnection alive past close() anyway. Bumping the dcClosed timeout alone would not help: once the transport is gone the response can never be sent. Co-Authored-By: Claude Opus 4.8 <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.
Fixes the intermittent Linux-CI failure of the Scenario 1 close test (
webdartc closes the data channel → both peers observe onclose), seen on #43's run:waitFor dcClosed timed out after 10s.Root cause (a teardown race in the e2e helper, not a library bug)
Closing a data channel is a bidirectional SCTP stream reset (RFC 8831 §6.7):
onClosefires — and sends its own reciprocal Outgoing reset request.onclose(→ browserdcClosed) only once we answer that reciprocal request.The offerer helper completed on its own
onCloseand immediately calledpc.close(). The failing run's last inbound chunk was Chrome's Response alone (82 00 00 10 / 00 10 00 0c / …/ 00 00 00 01= RE-CONFIG → Response param → result=1); Chrome's reciprocal request hadn't arrived yet. By the time it did, webdartc's transport was already torn down, so the response was never sent and Chrome'sonclosenever fired →dcClosedwait timed out.On fast runs (macOS/Windows/most Linux) Chrome's Response + reciprocal request arrive together / quickly, so webdartc answers before teardown — hence the flakiness.
Fix
Keep the PeerConnection alive ~2s after our
onClose(only on the close path) so the SCTP stack can answer Chrome's reciprocal reset and the bidirectional close completes. Helper-only change — real apps keep the PeerConnection alive pastclose(). Note: bumping thedcClosedtimeout alone would not help, since once the transport is gone the response can never be sent.Verified: the close test passes repeatedly locally; no library code touched.
🤖 Generated with Claude Code