Conversation
idy
added a commit
to GizClaw/pion-webrtc
that referenced
this pull request
Sep 11, 2026
pion-sctp now queues incoming streams instead of discarding the DATA of any stream beyond a 16-entry accept backlog (pion/sctp#499). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
idy
force-pushed
the
fix/accept-queue-backlog
branch
from
September 20, 2026 14:49
c56450e to
c71c0fc
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #499 +/- ##
==========================================
+ Coverage 89.04% 89.07% +0.02%
==========================================
Files 56 56
Lines 4756 4758 +2
==========================================
+ Hits 4235 4238 +3
+ Misses 521 520 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
createStream pushed new incoming streams onto a 16-entry channel with a non-blocking send and dropped the stream when it was full. Its DATA was then discarded without a SACK, so a peer opening more than 16 streams in a burst had to wait for T3-rtx (1s initial RTO, backing off) for every extra stream, and retransmissions kept being dropped while the application had not caught up. The non-blocking send dates back to pion#30: a blocking send made the read loop wait on the channel while holding the association lock, which the accepting goroutine needed. Keep incoming streams in an unbounded slice guarded by the association lock instead, and wake AcceptStream through a sync.Cond bound to that lock. Appending and signaling never block, and AcceptStream releases the lock while it waits, so the read loop can never wait on the application. Queued streams remain bounded by the stream ID space and their buffered bytes still count against the receive window. AcceptStream keeps its signature and close semantics: after the association closes it returns the streams already queued, then io.EOF. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
idy
force-pushed
the
fix/accept-queue-backlog
branch
from
September 21, 2026 18:32
c71c0fc to
a5be0f9
Compare
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.
What changed
Replace the 16-entry
acceptChwith an unbounded queue of incoming streams guarded by the association lock, and async.Condbound to that lock to wakeAcceptStream.createStreamalways registers the stream and appends it to the queue; it no longer returns nil, soacceptPayloadDatano longer discards DATA for a new stream.AcceptStreamreturns the head of the queue, waits on the condition variable while the queue is empty, and passes the wakeup on when more streams remain. Its signature is unchanged.readLoopmarks the queue closed and wakes all waiters instead of closing the channel. As before,AcceptStreamfirst returns the streams already queued and thenio.EOF.Why
When a peer opens more than 16 streams in a burst (e.g. WebRTC DataChannels opened in quick succession), the non-blocking send to the full
acceptChdropped the new stream and its DATA was discarded without a SACK. The sender had to wait for T3-rtx (1 s initial RTO, backing off), and retransmissions kept being dropped while the application was still catching up. A single packet can carry enough new-stream DATA chunks to fill the channel, and the accepting side usually cannot run in between because replying to the stream (e.g. a DCEP ACK) needs the association lock that the read loop holds. We measured over 1000 dropped streams and 3–4 s tail latency with 150 concurrent opens on loopback.The non-blocking send was introduced for #30: with a blocking send, the read loop waited on the full channel while holding the association lock, and the goroutine calling
AcceptStreamneeded that same lock to make progress, so both sides deadlocked. The new queue cannot reintroduce that: the read loop only appends to a slice and callsCond.Signal, neither of which blocks, andAcceptStreamreleases the lock while it waits inCond.Wait.The queue does not need a fixed bound: queued streams are limited by the stream identifier space, their buffered bytes still count against the receive window, and a peer can already open that many streams today if the application accepts fast enough.
Validation
TestAssocAcceptBacklogBurst: 64 streams opened and written while the server does not accept; all DATA is acknowledged, all 64 are then accepted with the right payloads, no T3 timeouts and well under the initial RTO (fails on main: the DATA is never acknowledged)TestAssocAcceptStreamAfterClose: queued streams are returned after close beforeio.EOF, and close wakes blocked callersgo test -race ./..., golangci-lint,GOOS=js GOARCH=wasm go vet ./...🤖 Generated with Claude Code