DataChannel: add bufferedAmount back-pressure surface (W3C §6.2)#45
Merged
Conversation
DataChannel had no flow-control surface: send()/sendBinary() pushed to SCTP with no visibility into how much was still in flight, so callers couldn't back-pressure large transfers. - SCTP: tally acked application bytes per stream when a SACK clears the retransmit queue (excluding DCEP control + the empty-message padding byte) and report them via a new onBytesAcked callback. - DataChannel: bufferedAmount (un-acked app bytes; += on send, -= on ack), bufferedAmountLowThreshold, and onBufferedAmountLow (fires on the downward threshold crossing). PeerConnection routes onBytesAcked to the owning channel. This gives app-level back-pressure: a caller that pauses while bufferedAmount is high and resumes on onBufferedAmountLow is paced by the peer's SACK rate. (Internal SCTP send flow control — holding chunks when the remote a_rwnd is exhausted — and binaryType are left as BACKLOG follow-ups; binaryType has no Dart analog since messages are always Uint8List.) Tested: SCTP onBytesAcked accounting (per-stream, empty=0) via two state machines; and the full bufferedAmount lifecycle against real Chrome in Scenario 1 (rose to 66583, drained to 0, onBufferedAmountLow fired). The stats loopback harness was extracted to test/peer_connection/loopback.dart for reuse. A separate finding — webdartc↔webdartc data channels never finish the DCEP open — is recorded in BACKLOG (it blocked a pure-loopback DC test). 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.
Addresses the DataChannel flow-control gap from the RFC/W3C divergence audit.
Problem
DataChannelhad no flow-control surface:send()/sendBinary()pushed straight to SCTP with no visibility into how much was still in flight, so callers couldn't back-pressure large transfers.Change
onBytesAcked(streamId, bytes)callback — same streamId fan-out idiom asonData/onStreamReset.bufferedAmount(un-acked app bytes;+=on send,-=on ack),bufferedAmountLowThreshold, andonBufferedAmountLow(fires on the downward threshold crossing).PeerConnectionroutesonBytesAckedto the owning channel.This gives app-level back-pressure: a caller that pauses while
bufferedAmountis high and resumes ononBufferedAmountLowis paced by the peer's SACK rate.Scope / follow-ups (BACKLOG)
bufferedAmountis un-acked (sent-but-not-acked) rather than the W3C "queued-but-not-yet-sent", becausesendDatatransmits immediately — documented on the API and in BACKLOG.a_rwndis exhausted) andbinaryType(no Dart analog — messages are alwaysUint8List) are left as BACKLOG items.onOpennever fires in pure loopback; DC e2e tests all use a browser). Recorded in BACKLOG — it's why the integration test runs against Chrome rather than loopback.Tests
onBytesAcked(buffered_amount_test.dart): per-stream tally, empty-message = 0, two state machines.bufferedAmount rose to 66583, drained to 0, onBufferedAmountLow fired.dart analyzeclean; 664 unit + 22 e2e pass. Reviewed with/simplify.🤖 Generated with Claude Code