Skip to content

Reuse DataChannel IDs safely within negotiated SCTP limits - #3491

Open
idy wants to merge 12 commits into
pion:mainfrom
GizClaw:fix
Open

Reuse DataChannel IDs safely within negotiated SCTP limits#3491
idy wants to merge 12 commits into
pion:mainfrom
GizClaw:fix

Conversation

@idy

@idy idy commented Aug 7, 2026

Copy link
Copy Markdown

What changed

  • reuse DataChannel IDs only after SCTP reports reset completion
  • keep overlapping and detached DataChannel generations associated with the correct stream ID
  • classify locally opened channels even when they are created after SCTP startup
  • enforce the negotiated SCTP stream limit for generated and explicit DataChannel IDs
  • roll back transport membership and ID reservations when opening a channel fails
  • expose a separate SCTP handshake retransmission setting

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 replace directive 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 ./...
  • affected DataChannel race tests repeated successfully under go test -race
  • go vet ./...
  • go mod tidy -diff
  • staticcheck -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/main checkout and do not produce race-detector reports; the DataChannel-focused race suite passes.

idy added 9 commits August 6, 2026 21:01
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
idy marked this pull request as ready for review August 7, 2026 07:40
idy added 3 commits August 7, 2026 16:01
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant