Reuse DataChannel IDs safely within negotiated SCTP limits - #3491
Open
idy wants to merge 12 commits into
Open
Conversation
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)
Update the SCTP fork pin so DataChannel identifiers are released only after both stream reset directions complete.
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)
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)
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)
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)
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
marked this pull request as ready for review
August 7, 2026 07:40
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
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
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
Why
DataChannel IDs are SCTP stream IDs. Reusing an ID before both reset directions complete can associate delayed reset or acknowledgement traffic with a new channel generation. Never releasing an ID avoids that race but eventually exhausts the negotiated stream range.
This change tracks local generations through reset completion so IDs can be reused without allowing traffic from an older generation to affect the new channel. It also rejects explicit IDs outside the negotiated range and cleans up failed opens.
Dependencies and relationship to existing work
This PR depends on pion/sctp#485. The temporary
replacedirective pins the reviewed fork commit containing that SCTP work; it should be replaced with an upstream release after the SCTP change lands.This is an alternative implementation that covers the goals of #3405 and adds handling for overlapping generations, detached and dynamically created channels, explicit-ID bounds, and failure rollback.
This PR is not intended to invalidate the work in #3405. If maintainers prefer to continue with #3405, please feel free to close this PR and reuse or adapt any tests and fixes that are useful.
Validation
go test ./...go test -racego vet ./...go mod tidy -diffstaticcheck -checks 'all,-SA6002,-ST1016' .The full race suite also reaches two existing TrackLocal timestamp and sequence-number timing assertions. They fail identically on a clean
upstream/maincheckout and do not produce race-detector reports; the DataChannel-focused race suite passes.