Repository navigation
trystero: hold a second connection until the peer shows which it keeps (fixes interop room-leave flake) - #9
Merged
Conversation
…which it keeps, so that a crossed pair no longer makes a Trystero JS page report a peer error
The interop lane's "one room leaving" scenario failed on main (run 44726002584) with
"console.error Trystero peer error: OperationError" before any room left: its two rooms
negotiated at once, the two channels opened in one order on the page and in the other natively,
and each side kept the one that opened first on its side, as Trystero's rule says. The native app
then closed its second connection at once, which was the one the page kept, just as the page sent
its first frames on it. libdatachannel ends an association with a stream reset and a SHUTDOWN,
its ABORT a moment later, where a browser's ABORT follows its reset at once: Chrome's channel
completed the closing procedure (or saw the SHUTDOWN) with a send failed in between, closed with
that failure ("data-channel-failure", or "Failure to send data"), and Trystero JS, which ignores
only an abort, logged a peer error. Chrome's log showed the reset, "Send failed INVALID_STATE",
then the error, ahead of the ABORT; in 1,800 two-room meetings the page reported 6 such errors
among 46 crossed pairs.
The app now holds such a second connection, unused, until the peer shows which it keeps: a frame
on the first, which closes the second as the peer closes its own (and a connection opened after
the peer sent on the first is closed at once); the peer closing the first, which Trystero JS does
in a crossed pair, after which the second replaces the first with the frames it received; or,
for the higher id, a frame on the second, which then replaces the first, since a peer of this
port holds its second too. One the peer leaves alone is closed after 2 s by the higher id and
after 10 s by the lower id. No connection the peer uses is closed, so the 1,800 meetings showed
no error, and the scenario passed 600 runs of 600.
The memory relays now hold a frame that reaches an end before it opens until it opens, as a real
channel delivers what follows its opening message; the crossed-pair test now checks the lower
id keeps the peer throughout.
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 failure of interop_native's "Native C++: one room leaving, either side, leaves the other room and the connection" on webcpp main (CI run 44726002584,
js#1: console.error Trystero peer error: OperationError).Cause
The failure happens before any room leaves, while the scenario's two rooms negotiate at once. Sometimes the two connections cross: each side keeps the connection whose channel opened first on its side (Trystero's rule,
dist/shared-peer.mjs:105-108), and the two sides pick different ones. The native app then closed its second connection at once. That was the connection the page kept, and the page was just starting to send on it.libdatachannel ends an association with a stream reset and a SHUTDOWN, and its ABORT comes a moment later. When a browser closes, its ABORT follows the reset at once. With the native close, Chrome's channel finished the closing procedure, or saw the SHUTDOWN, while one of the page's sends was in flight. It failed that send and closed with
data-channel-failure. Trystero JS ignores only an abort (dist/peer.mjs:157-160), so it logged a peer error.Evidence:
OnIncomingStreamsReset, thenSend failed INVALID_STATE, thenOnStreamsResetPerformed, thenDataChannel error: "", and only after that the native ABORT.Making the native close W3C-like does not help. I tried closing the connection before its channel, so that no stream reset is sent. That made things worse: Chrome then reported
Failure to send datafrom the SHUTDOWN in 6 of 20 crossed pairs. libdatachannel has no way to close with an ABORT alone.Fix
The app no longer closes a second connection to a peer at once. It holds it, unused, until the peer shows which connection it keeps:
Results
Tests and docs
app_impltests cover each outcome: the second closed, closed at once, replaced by the lower id, taken by the higher id, and the deadlines.connectiontests coverused,ended_by_transportandreplay.sharedtest now checks that the lower id never loses the peer.differences.adocnow describes the change, with the reason, and the changelog line is updated.The superproject PR bumps the gitlink and updates CODING-GUIDELINES.md's adoption decision.
🤖 Generated with Claude Code