Skip to content

Limit datachannel IDs based on SCTP stream Ids - #3405

Open
pando-emil wants to merge 3 commits into
pion:mainfrom
pando-emil:limit-datachannels-to-sctp-limits
Open

Limit datachannel IDs based on SCTP stream Ids#3405
pando-emil wants to merge 3 commits into
pion:mainfrom
pando-emil:limit-datachannels-to-sctp-limits

Conversation

@pando-emil

Copy link
Copy Markdown

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.

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.
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
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
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