Skip to content

Fix two of E18's three close-flush data-loss bugs - #116

Closed
lann wants to merge 1 commit into
mainfrom
e18-close-flush-fixes
Closed

Fix two of E18's three close-flush data-loss bugs#116
lann wants to merge 1 commit into
mainfrom
e18-close-flush-fixes

Conversation

@lann

@lann lann commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

E18 is now fully diagnosed: the libwebrtc reference peer is blameless. Its immediate close-after-send (spec-legal; libwebrtc flushes before the SCTP reset per RFC 8831 §6.7) coalesces the tail DATA and the reset RECONFIG into one burst, and three distinct receiver-side bugs mishandled it. This PR fixes two and documents all three in TODO E18.

Fixed here

  1. rtc-sctp discarded received-but-undelivered messages on an incoming stream reset (reference-x-wasmtime, answerer: receive: closed). reset_streams_if_anyunregister_stream dropped the stream's reassembly queue with reassembled-but-unread messages inside, before the driver polled the pending Readable events. Fixed by sctp: don't discard received-but-undelivered data on incoming stream reset lann/rtc#1; the [patch.crates-io] pin moves to lann/rtc rev 353a84a = upstream a10cd2c (the existing E4/E6 srflx fix) + that cherry-pick, so nothing is lost.
  2. Reference peer wait_open rejected an already-closing incoming channel (wasmtime-x-reference, answerer: channel closed before open). A remote-announced channel that reads closing/closed was necessarily open first and its messages are already queued; open→send→close can land inside one 25ms poll interval. Remote channels now count that state as opened; locally created channels still fail.

Also: recv_sequence failures (conformance guest + reference peer) now report (after N of M messages), which is what made the diagnosis tractable.

Remaining (tracked in E18, not fixed here)

  1. The webrtc 0.20 driver delivers a data-channel close ahead of already-received messages: its loop runs poll_events() before poll_reads(), and close/data travel different core queues. Fix belongs upstream in webrtc-rs/webrtc.
  • reference-x-jco-node failures with the same trigger are E16 (node-datachannel TSFN race).

Verification

20-iteration channel-close-flush loops on reference-x-wasmtime + wasmtime-x-reference: bugs 1 and 2 no longer reproduce (0/40 for the wait_open shape; SCTP traces show all payloads reaching the driver); remaining failures (4/20 iterations) are all bug 3's shapes. just fmt-check, just clippy, just test green.

Supersedes #115.

The libwebrtc reference peer's immediate close-after-send coalesces the
tail DATA chunks and the SCTP stream-reset RECONFIG into one network
burst; three distinct receiver-side bugs mishandled it. This fixes two:

- Pin rtc to lann/rtc rev 353a84a (upstream a10cd2c plus the cherry-pick
  of lann/rtc#1): rtc-sctp no longer discards received-but-undelivered
  messages when an incoming stream reset arrives in the same input batch
  as the data — stream teardown is deferred until the consumer drains
  the reassembly queue.

- The reference peer's wait_open now treats an already-closing
  remote-announced channel as opened: announcement implies the open
  transition happened, and its messages are already queued in the
  wiring, so a peer landing open→send→close inside one 25ms poll
  interval is not an error.

Also make recv_sequence failures in the conformance guest and the
reference peer report how many messages had arrived, distinguishing
partial delivery from a receive path that never yielded.

The third bug — the webrtc 0.20 driver delivering a data-channel close
ahead of already-received messages (poll_events runs before poll_reads;
close and data travel different queues) — remains; TODO E18 records the
full diagnosis.

Verified with 20-iteration channel-close-flush interop loops
(reference-x-wasmtime + wasmtime-x-reference): the wait_open failure and
the rtc-sctp loss no longer reproduce; remaining failures are all the
webrtc driver reorder.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lann

lann commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #139, which ports this onto main (post-#135/#137 tree): same two fixes and diagnostics; the rtc fix now rides pinned git dependencies (lann/rtc#1 rebased to 89f518ea, consumed through a lann/webrtc submodule-redirect branch) instead of [patch.crates-io], since the rebase sits on unreleased 0.21.0 and webrtc master vendors rtc as a submodule path dependency.

@lann lann closed this Aug 6, 2026
lann added a commit that referenced this pull request Aug 6, 2026
Fix two of the close-flush data-loss bugs (#116 ported to main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant