Skip to content

fix(sctp): report duplicate TSNs and bound SACKs - #301

Merged
rainliu merged 2 commits into
webrtc-rs:masterfrom
volchanskyi:sctp-duplicate-reports
Nov 11, 2026
Merged

rainliu merged 2 commits into
webrtc-rs:masterfrom
volchanskyi:sctp-duplicate-reports

Conversation

@volchanskyi

Copy link
Copy Markdown
Contributor

The receiver never reports a TSN it got twice. handle_data only calls PayloadQueue::push, which is what records a duplicate, when can_push returns true, and can_push is false for exactly those chunks. So pop_duplicates() always comes back empty and every SACK goes out with zero duplicate TSNs. A packet carrying nothing but repeats also waits for the delayed-ack timer, but RFC 9260 section 6.2 says that SACK MUST go out immediately.

This change records each repeat and sends the SACK at once. The repeat list is capped at 20 between SACKs, the same cap dcSCTP and usrsctp use (Linux uses 16). Following the RFC 9260 section 3.3.4 example, a TSN received three times is listed twice.

The SACK is also bounded by the association's MTU now. Gap blocks closest to the cumulative TSN go in first, then whatever repeats still fit. Today the gap list has no limit, so a large window with heavy loss can produce a SACK bigger than one packet (one of the new tests builds an 8028-byte SACK against a 1428-byte MTU). pion/sctp#493 fixed the same thing. The doc comment on SettingEngineBuilder::with_sctp_mtu previously said SACKs ignore the MTU, so it now says they don't.

pion/sctp has the same receiver bug (receivePayloadQueue.push is also guarded by canPush).

Tests (association/duplicate_report_test.rs):

  • a repeat below the cumulative TSN is reported, the SACK is immediate, and the next SACK starts with an empty list
  • a repeat of a chunk held above a gap is reported
  • a TSN received three times is listed twice
  • a repeat bundled with new data is reported and the new data is kept
  • at most 20 repeats are kept between SACKs
  • a SACK fits in one packet, keeping the gaps nearest the cumulative TSN
  • repeats fill whatever room the gaps leave

cargo fmt --check, cargo clippy, cargo test --workspace, the doc tests and both scripts/check-*.py checks pass locally on rustc 1.99.1.

The receiver never listed a repeated TSN: handle_data calls
PayloadQueue::push, which records duplicates, only after can_push has
already turned repeats away. It also delayed the SACK for a packet that
held only repeats, which RFC 9260 section 6.2 says MUST be sent at once.

Repeats are now recorded (at most 20 between SACKs, as dcSCTP and usrsctp
keep) and answered with an immediate SACK. The SACK keeps within the
association's MTU: gap blocks nearest the cumulative TSN first, then the
repeats that still fit.
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.51%. Comparing base (3e0bb17) to head (e181e5e).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #301      +/-   ##
==========================================
+ Coverage   88.49%   88.51%   +0.01%     
==========================================
  Files         510      511       +1     
  Lines       75230    75334     +104     
==========================================
+ Hits        66575    66680     +105     
+ Misses       8655     8654       -1     
Flag Coverage Δ
aws-lc-rs 88.27% <100.00%> (+0.01%) ⬆️
ring 88.45% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rainliu
rainliu merged commit 0fbcaa7 into webrtc-rs:master Nov 11, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants