Skip to content

fix(gateways): bound WebRTC mux and RTMP pre-play state, accept SDP MIME params, end HLS holds and transcoder on close - #9342

Merged
kixelated merged 10 commits into
mainfrom
quest/m1/precut-audit/gateways-bounds-and-lifecycles
Nov 22, 2026
Merged

kixelated merged 10 commits into
mainfrom
quest/m1/precut-audit/gateways-bounds-and-lifecycles

Conversation

@kixelated

@kixelated kixelated commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes five pre-cut audit findings in the gateways (the gateways-bounds-and-lifecycles quest, finished by this PR).

Changes

  • moq-webrtc mux: each session keeps a short list of the addresses it holds or claims, at most MAX_ADDRS (16). The address it signed least recently goes first. Only a binding request signed with the session's own ICE password caches an address, so the attacker is a session's own peer signing from rotating spoofed sources. That peer now fills only its own 16 slots. Consent checks re-sign the address in use every few seconds, so a real peer keeps it. A session's teardown removes its own entries in O(16) instead of sweeping every session's entries.
  • moq-webrtc WHIP/WHEP: the two copies of is_sdp merge into server::is_sdp, which accepts MIME parameters (application/sdp; charset=utf-8).
  • moq-rtmp play: while a play waits for its broadcast, catalog, and first FLV header (up to 3 × PLAY_RESOLVE_TIMEOUT), feed_input used to queue every session result. A client flooding commands that owe replies grew that queue without limit. It now writes owed replies before reading more, so work holds at most one read's results and a client that floods without reading stalls on its own TCP window. To stay safe to drop inside select!, it uses single write calls and trims the sent bytes off the front packet. It drops events, which nothing before playback acts on.
  • moq-rtmp selection: the single-track branch of play_selection now checks only enabled renditions. Before, a client that could play only a disabled rendition was accepted, then got no video, because select never picks disabled tracks. It is now refused and told which FourCC is missing. With no enabled renditions of a kind, nothing is refused.
  • moq-hls: clear, finish, and cut release state.waiting, the subscriptions held for a catalog that has no join interval yet. Before, a set that ended before declaring an interval kept every track subscribed for as long as any consumer held the shared state.
  • moq-transcode: Transcoder::run's serve loop breaks on source.closed(). Before, a source that closed while its catalog track stayed open hung the transcoder. It now winds down the same way a catalog end does: it finishes the derived catalog.

Public API: none. Wire: none.

Validation

  • Regression tests, each confirmed to fail without its fix:
    • server::mux::tests::a_session_holds_its_most_recent_addresses: 1,000 spoofed sources leave 16. The address the peer keeps refreshing survives. Teardown leaves the other session's address.
    • server::tests::sdp_content_type_ignores_parameters
    • server::tests::a_flooding_viewer_cannot_grow_the_pre_play_queue: the old feed_input queued 4,882 replies. The new one holds at most 1, and the flooder blocks.
    • play_selection_picks_the_best_playable_{rendition,audio}, extended with disabled-only cases.
    • export::renditions::tests::an_ended_set_releases_its_held_tracks: the old code fails with "the hold outlived the set".
    • tests::a_closed_source_ends_the_serve_loop: the old code timed out after 5 s.
  • Real binary: moq --listen-unix-bind … --auth-public "" --broadcast cam import webrtc --listen 127.0.0.1:18080, then POSTed an Opus offer with curl:
    • application/sdp → 201 with an SDP answer
    • application/sdp; charset=utf-8 → 201 with an SDP answer
    • text/plain → 400 invalid SDP: expected Content-Type: application/sdp
  • Full cargo test for moq-webrtc (server), moq-rtmp, moq-hls --lib, and moq-transcode --lib, plus just check: all pass.

Decisions

  • Pullfrog's two post-queue findings, both fixed: is_sdp now sits above delete's doc comment, and feed_input returns on a queued stop before writing any reply, so a stop behind a reply the viewer never reads ends the wait (a_stop_behind_an_unread_reply_ends_the_wait).

Choices made without asking

  • MAX_ADDRS = 16 per session, evicting the least recently signed address. A WebRTC peer has a handful of candidates. Total mux state is now sessions × 16.
  • In the transcoder, a closed source finishes the derived catalog cleanly, like a catalog end. It does not abort. Only the prologue still returns Cancel, since there a source gone before its ladder exists is no clean end.

Caused by

  • moq-dev/moq#1864 - the shared-port mux cached addresses per session with no bound, and its teardown swept every session's entries (found by check, the pre-cut audit)
  • moq-dev/moq#1528 - WHIP/WHEP matched Content-Type exactly (found by check)
  • moq-dev/moq#1829 - RTMP play queued pre-playback session results without writing them (found by check)
  • moq-dev/moq#4293 - single-rendition egress counted disabled renditions as playable (found by check)
  • moq-dev/moq#7652 - its interval-less holds were released only by a later sync (found by check)
  • Transcoder: no single PR. The serve loop never watched the source; moq-dev/moq#9120 added the watch to the prologue only.

Follow-ups

None.

Models

Size: M
Implementer: Claude Code, claude-opus-5-5, unknown effort (arm A)
Implementer: Claude Code, claude-opus-5-5, unknown effort (iterate, XS, arm A)

🤖 Generated with Claude Code

Review

Rewritten by quest review after each round.

  • Head: 57902a5

  • Base: origin/main at f1b6e06

  • Risk: medium, Gateway routing, RTMP playback, HLS cleanup, and transcoder shutdown changes could disrupt streams for users, but preserve public APIs and wire formats and are fully undone by a revert.

  • Classified: medium by Codex, gpt-6.1-sol, low effort, session 01a201d6-2232-7373-befb-cc25d2c54b44

  • Reviewer: Codex, gpt-6.1-sol, high effort

  • Session: 01a20188-bdfd-7b53-be0a-a07d4a0524d2, round 3

  • Score: 10/10, The incremental changes correctly prioritize queued playback stops and fix misplaced documentation, with no new issues found by code inspection; builds and tests were not run.

  • Rounds: 3; first round 1 (medium 1); findings 1 (medium 1): fixed 1, refuted 0, open 0

  • Findings: none

kixelated and others added 8 commits November 21, 2026 20:03
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Fix gateway memory bounds, MIME parsing, disabled-track selection, and shutdown lifecycles fix(gateways): bound WebRTC mux and RTMP pre-play state, accept SDP MIME params, end HLS holds and transcoder on close Nov 22, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 22, 2026 04:38
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 9 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c29d3cf4-91b4-4780-80e7-6bd8ab027122
Commits

Reviewing files that changed from the base of the PR and between e140dae and 57902a5.

Files selected for processing: 8

  • quest/m1/precut-audit/gateways-bounds-and-lifecycles.md
  • rs/moq-hls/src/export/renditions.rs
  • rs/moq-rtmp/src/server.rs
  • rs/moq-transcode/src/lib.rs
  • rs/moq-webrtc/src/server/mod.rs
  • rs/moq-webrtc/src/server/mux.rs
  • rs/moq-webrtc/src/server/whep.rs
  • rs/moq-webrtc/src/server/whip.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@kixelated
kixelated enabled auto-merge November 22, 2026 04:40

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — two rough edges inline.

Approach: sound. Each finding is fixed at its source: a per-session address list in the mux, a shared MIME check, writing owed replies before reading in feed_input, and lifecycle hooks in HLS and the transcoder.

Reviewed changes

I reviewed all 8 files across the 9 commits, including the mux routing paths, the Play::accept call sites of feed_input, play_selection's use of enabled(), HLS sync after close, and the transcoder serve loop.

  • WebRTC mux bounds: each session keeps at most MAX_ADDRS (16) held or claimed addresses, dropping the least recently signed. release only removes an entry that still points to its own Arc<Entry>, so stale entries in a dead holder's list are harmless, and teardown no longer sweeps every session.
  • is_sdp dedup: one server::is_sdp now serves both WHIP and WHEP. It compares only the MIME type, ignoring parameters such as charset, case-insensitively.
  • RTMP pre-play backpressure: feed_input writes the replies it owes before it reads again. It uses single write calls and trims the sent bytes, so dropping it inside select! loses no bytes.
  • RTMP disabled renditions: single-track selection now only considers enabled() renditions. enabled() is ranked() filtered, so the codec named in the refusal is still the best-ranked one.
  • HLS holds: clear, finish and cut now empty state.waiting. After close, sync can't refill it because state.write() fails.
  • Transcoder: the serve loop now stops on source.closed() and finishes the derived catalog cleanly.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

Comment thread rs/moq-webrtc/src/server/mod.rs Resolved
Comment thread rs/moq-rtmp/src/server.rs Resolved
@moq-bot
moq-bot Bot disabled auto-merge November 22, 2026 04:42
@moq-bot

moq-bot Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

quest land watch: ended this pull request's pick, disarming its auto-merge, since its head e67e5f2 is held by finding by pullfrog[bot]: is_sdp was inserted between delete's doc comment and delete. Rustdoc now joins both comments onto is_sdp ("Share (#9342 (comment)); finding by pullfrog[bot]: feed_input now sees the stop only when it reaches the front of work. If it is queued behind a reply whose write is (#9342 (comment)). Push a fix, or answer each by a thread reply or a comment linking its review or decision, then land it again.

(written by quest land watch)

… doc on delete

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

I reviewed the one new commit since the prior pullfrog review (e67e5f2..57902a5).

  • RTMP pre-play stop: feed_input now checks all of work for a queued PlayStreamFinished before any write and returns at once. A stop behind a reply the viewer never reads ends the wait, and a_stop_behind_an_unread_reply_ends_the_wait pins it with a 1-byte pipe.
  • is_sdp doc placement: is_sdp now sits above delete's doc comment, so each item keeps its own docs.

Pullfrog  | View workflow run | Using claude-sonnet-5-5 | 𝕏

@kixelated
kixelated added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 1cb22d4 Nov 22, 2026
9 checks passed
@kixelated
kixelated deleted the quest/m1/precut-audit/gateways-bounds-and-lifecycles branch November 22, 2026 06:22
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.

1 participant