Limit datachannel IDs based on SCTP stream Ids - #3405
Open
pando-emil wants to merge 3 commits into
Open
Conversation
NOTE! This patch depends on a corresponding patch in sctp that adds the numInboundStreams, numOutboundStreams and OnStreamResetComplete functions on Association. When an SCTP association is setup, the number of streams in each direction is "negotiated" between the peers. The max number of streams also determines the maximum ID a stream can be identified as. This patch makes sure to not trying to use stream IDs outside the valid range. The patch also makes sure IDs can be reused after reset. Before this patch, you could never open datachannels more than 65535 / 2 times within a session, even you only have one in use at a time.
JoTurk
self-requested a review
April 10, 2026 07:12
12 tasks
idy
added a commit
to GizClaw/pion-webrtc
that referenced
this pull request
Aug 6, 2026
Long-lived SCTP associations retained every allocated DataChannel ID after channels closed, eventually exhausting the negotiated stream space. Use the GizClaw SCTP reset-completion contract, release IDs only after completed resets, and bound allocation to negotiated stream counts. The close path unregisters the callback before aborting outside the transport lock to avoid lock inversion. Refs: #1, GizClaw/gizclaw#776, pion#3405 Generated with [Codex](https://github.com/openai)
idy
referenced
this pull request
in GizClaw/pion-webrtc
Aug 7, 2026
idy
referenced
this pull request
in GizClaw/pion-webrtc
Aug 7, 2026
Update the SCTP fork pin so DataChannel identifiers are released only after both stream reset directions complete.
idy
referenced
this pull request
in GizClaw/pion-webrtc
Aug 7, 2026
idy
referenced
this pull request
in GizClaw/pion-webrtc
Aug 7, 2026
The SCTP accept loop kept only the DataChannels that existed when the transport started. ACKs for later local channels were therefore parsed as remote OPEN packets and could close the shared association under load. - Classify accepted streams against the live local DataChannel registry - Track whether each channel originated remotely to avoid stale ID matches - Cover a second local channel created after SCTP startup with a distinct ID - Pin the SCTP fork commit that preserves established sessions on duplicate INIT Generated with [Codex](https://github.com/openai)
idy
referenced
this pull request
in GizClaw/pion-webrtc
Aug 7, 2026
Expose a handshake-specific SCTP retransmission limit and pass it to the forked SCTP association without changing DATA/T3, reconfiguration, or shutdown timers. Pin the SCTP fork commit that provides the compatible option.\n\nRefs: GizClaw/gizclaw#700\nUpstream-base: 381746d534f410658e0751cd3768b17727950027\n\nGenerated with [Codex](https://github.com/openai)
idy
referenced
this pull request
in GizClaw/pion-webrtc
Aug 7, 2026
Detached DataChannels leave the transport registry before their inbound ACK arrives. Track each local SCTP stream generation directly so the accept loop cannot parse those ACKs as remote OPEN messages, including when stream IDs overlap across delayed resets. Refs: GizClaw/gizclaw#699, GizClaw/gizclaw#700, GizClaw/gizclaw#776 Generated with [Codex](https://github.com/openai)
idy
referenced
this pull request
in GizClaw/pion-webrtc
Aug 7, 2026
SCTP can recreate a Stream object while completing a reset. Track ordered local DataChannel generations by stream ID so inbound ACKs remain classified correctly and delayed resets release only the oldest generation. Refs: GizClaw/gizclaw#699, GizClaw/gizclaw#700, GizClaw/gizclaw#776 Generated with [Codex](https://github.com/openai)
idy
referenced
this pull request
in GizClaw/pion-webrtc
Aug 7, 2026
Explicit DataChannel IDs could bypass the negotiated SCTP stream bound, and failed opens left stale transport entries and ID reservations behind. - Reject explicit IDs outside the negotiated bidirectional stream range - Roll back transport membership and reservations when local opens fail - Pin the SCTP fork revision that safely handles reset retransmissions - Cover the invalid and valid boundary paths plus failure cleanup Generated with [Codex](https://github.com/openai)
idy
referenced
this pull request
in GizClaw/pion-webrtc
Aug 7, 2026
Avoid immediately reusing the lowest parity-correct SCTP stream after reset completion. Advance allocations through the negotiated stream space and wrap only after a full cycle, while preserving reservation checks and bounded ID reuse. Generated with Codex
idy
referenced
this pull request
in GizClaw/pion-webrtc
Aug 7, 2026
idy
referenced
this pull request
in GizClaw/pion-webrtc
Aug 7, 2026
Allow controlled APIs to set inbound and outbound SCTP stream counts while retaining the existing default when either value is zero. Pass the limits through normal and SNAP association setup so bounded end-to-end DataChannel ID reuse tests can negotiate a small real stream space.\n\nRefs: GizClaw/gizclaw#776\nUpstream-base: 381746d
12 tasks
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.
NOTE! This patch depends on a corresponding patch in sctp (pion/sctp#463) that adds the numInboundStreams, numOutboundStreams and OnStreamResetComplete functions on Association.
When an SCTP association is setup, the number of streams in each direction is "negotiated" between the peers. The max number of streams also determines the maximum ID a stream can be identified as.
This patch makes sure to not trying to use stream IDs outside the valid range.
The patch also makes sure IDs can be reused after reset. Before this patch, you could never open datachannels more than 65535 / 2 times within a session, even you only have one in use at a time.