Skip to content

Fix rfc8888 implementation#425

Merged
5ur3 merged 3 commits into
pion:mainfrom
5ur3:fix-rfc8888-implementation
Jul 6, 2026
Merged

Fix rfc8888 implementation#425
5ur3 merged 3 commits into
pion:mainfrom
5ur3:fix-rfc8888-implementation

Conversation

@5ur3

@5ur3 5ur3 commented Jul 6, 2026

Copy link
Copy Markdown
Member

Description

Issue 1 - unbounded growth of streamLog.log (memory exhaustion).

Entries are only removed while metricsAfter iterates upward from nextSequenceNumberToReport, so any entry left below that pointer is never freed. An entry lands below the pointer three ways:

  1. A burst of more than maxReportBlocks packets between metricsAfter calls trips the cap, which advances the pointer past entries it hasn't deleted.
  2. A permanently lost packet stalls the pointer; as later packets keep arriving, numReports exceeds maxReportBlocks and the same cap advances the pointer past still-stored sequence numbers. (1 and 2 share one root cause.)
  3. A late or duplicate packet whose unwrapped sequence number is already below the pointer is inserted directly by add().

Issue 2 - possibility of make() called with negative len.

metricsAfter allocates its metricBlocks slice with a length up to maxReportBlocks. That value is derived in recorder.go from maxSize and the number of distinct SSRCs; with enough SSRCs in a session it becomes negative, so make() is called with a negative length and panics.

@Sean-Der Sean-Der requested a review from Copilot July 6, 2026 18:11
@Sean-Der

Sean-Der commented Jul 6, 2026

Copy link
Copy Markdown
Member

Thanks @5ur3! I will get this merged now and cut a release :)

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.05%. Comparing base (34107a4) to head (b5a0882).

Files with missing lines Patch % Lines
pkg/rfc8888/recorder.go 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #425      +/-   ##
==========================================
- Coverage   80.05%   80.05%   -0.01%     
==========================================
  Files          88       88              
  Lines        4608     4617       +9     
==========================================
+ Hits         3689     3696       +7     
- Misses        736      737       +1     
- Partials      183      184       +1     
Flag Coverage Δ
go 80.05% <83.33%> (-0.01%) ⬇️

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.

@5ur3

5ur3 commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

I will fix linter errors shortly

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses two correctness/stability issues in the RFC 8888 feedback implementation: preventing unbounded in-memory growth in per-stream packet logs and ensuring report-size budgeting cannot go negative (avoiding panics).

Changes:

  • Prevent streamLog memory growth by dropping late/duplicate packets below the report pointer and reclaiming skipped entries when applying the report-block cap.
  • Clamp the computed report-block budget to a non-negative value to avoid make() panics when many SSRCs are present.
  • Add tests covering both the stream-log reclamation behavior and the non-positive per-stream budget scenario.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/rfc8888/stream_log.go Drops packets below the report pointer and deletes log entries that would otherwise be skipped and leaked when capping report blocks.
pkg/rfc8888/stream_log_test.go Adds regression tests ensuring the stream log does not retain entries below the report pointer.
pkg/rfc8888/recorder.go Clamps report-block budget to avoid negative lengths in slice allocation.
pkg/rfc8888/recorder_test.go Adds test ensuring large SSRC counts don’t cause panics and produce empty per-stream metric blocks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/rfc8888/recorder.go Outdated
Comment on lines 51 to 53
maxReportBlocks := max((maxSize-12-(8*len(r.streams)))/2, 0)
maxReportBlocksPerStream := maxReportBlocks / len(r.streams)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that such division by zero is unreachable (len(r.streams) is at least 1 when this code is triggered)

@JoTurk JoTurk Jul 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both BuildReport and NewRecorder are public. so it's reachable in custom user code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoTurk should I update this PR manually? Or will you commit this suggestion?

@JoTurk JoTurk Jul 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up to you :) you can apply it and amend your commit if you want, so it doesn't create extra noisy commit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will just create extra commit myself

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you.

@5ur3 5ur3 force-pushed the fix-rfc8888-implementation branch from c22b4d6 to b5a0882 Compare July 6, 2026 18:43
@5ur3 5ur3 merged commit 16955aa into pion:main Jul 6, 2026
18 checks passed
@5ur3 5ur3 deleted the fix-rfc8888-implementation branch July 6, 2026 18:46
@JoTurk

JoTurk commented Jul 6, 2026

Copy link
Copy Markdown
Member

should have squash merged.

@5ur3

5ur3 commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

should have squash merged.

skill issue, I'm not using github a lot :) I'll remember that for next time

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.

4 participants