Skip to content

fix(jellycompat): reuse the play session for Static direct play instead of leaking one per request - #165

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
d3v1l1989:fix/jellycompat-static-directplay-session-leak
Jun 16, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
d3v1l1989:fix/jellycompat-static-directplay-session-leak

Conversation

@d3v1l1989

Copy link
Copy Markdown
Contributor

Problem

Clients that direct-play via GET /Videos/{id}/stream?…&Static=true never call
PlaybackInfo, so they send their own client-generated PlaySessionId and repeat
it on every byte-range request. resolvePlaybackRoute looked that id up, missed
(the server never minted it), returned ErrSessionNotFound, and HandleVideoStream
fell to createStaticPlaySession → a new upstream session for every request.

Each new session counts toward the per-user max_streams cap and only ages out
after the 45s activity grace, so a single direct play's range requests pile up
orphaned sessions and quickly trip the cap → 429 TooManyStreams, locking the
user out of their own playback. (Confirmed in real traffic: one playback's
PlaySessionId repeated 160+ times, each request minting a fresh session.)

Approach

When the provided PlaySessionId is unknown (or owned by another caller), fall
through to the existing CompatToken-scoped FindByRoute reuse instead of
erroring, so all of a direct play's requests share one session. Reuse stays scoped
to the caller's own token, so a guessed/foreign id cannot bind another user's
session.

Scope / what this does and doesn't do

  • Fixes the per-request leak (N sessions per direct play → 1).
  • Does not change the cap itself: 6+ genuinely distinct titles played within
    the 45s grace still legitimately hit max_streams (real concurrency, not a
    leak; activeCountLocked has no per-item dedup).
  • The fall-through applies to any /Videos/{id}/stream (and the subtitle path)
    with an unknown PlaySessionId, not strictly Static=true. This is safe: the
    play method is recomputed per-request from the resolved source's
    direct-play/stream flags, ensureUpstreamPlayback restarts the upstream session
    on a method mismatch, and reuse is CompatToken-scoped. Transcode/HLS manifest +
    segment handlers resolve sessions via playbackStore.Get directly and are
    unaffected.

Testing

  • New TestHandleVideoStream_StaticDirectPlayReusesSessionAcrossRequests asserts
    StartSession runs exactly once across 3 repeated Static requests carrying the
    same client PlaySessionId. Mutation-verified (revert → 3 calls → RED).
  • Existing Static-serve and no-Static-404 tests still pass.
  • gofmt/go vet clean; full internal/jellycompat suite green in the
    libvips-capable container.

AI-assisted: root-caused from production jellycompat request captures and reviewed
across regression / security / effectiveness passes; every line reviewed, and the
tests run and mutation-verified, by me.

…ad of leaking one per request

Clients that direct-play via /Videos/{id}/stream?Static=true never call
PlaybackInfo, so they send their own client-generated PlaySessionId and repeat
it on every range request. resolvePlaybackRoute looked that id up, missed (the
server never minted it), and returned ErrSessionNotFound — so HandleVideoStream
fell to createStaticPlaySession and started a *new* upstream session for every
request. Each counts toward the per-user max_streams cap and only ages out after
the 45s activity grace, so a single direct play's range requests pile up orphaned
sessions and quickly trip the cap -> 429 TooManyStreams, locking the user out of
their own playback.

When the provided PlaySessionId is unknown (or owned by another caller), fall
through to the existing CompatToken-scoped FindByRoute reuse instead of erroring,
so all of a direct play's requests share one session. Reuse stays scoped to the
caller's own token, so a guessed/foreign id cannot bind another user's session.
Adds a test asserting StartSession runs once across repeated Static requests.
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@d3v1l1989, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 58 minutes and 12 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f5c5135-9ddd-430d-b377-ad410c51f854

📥 Commits

Reviewing files that changed from the base of the PR and between 203d9be and 38ea6bb.

📒 Files selected for processing (3)
  • internal/jellycompat/audio_selection_test.go
  • internal/jellycompat/playback_static_directplay_test.go
  • internal/jellycompat/streams.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@Quick104

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@Quick104
Quick104 merged commit 4730775 into Silo-Server:main Jun 16, 2026
1 check passed
Quick104 pushed a commit that referenced this pull request Jun 17, 2026
…ad of leaking one per request (#165)

Clients that direct-play via /Videos/{id}/stream?Static=true never call
PlaybackInfo, so they send their own client-generated PlaySessionId and repeat
it on every range request. resolvePlaybackRoute looked that id up, missed (the
server never minted it), and returned ErrSessionNotFound — so HandleVideoStream
fell to createStaticPlaySession and started a *new* upstream session for every
request. Each counts toward the per-user max_streams cap and only ages out after
the 45s activity grace, so a single direct play's range requests pile up orphaned
sessions and quickly trip the cap -> 429 TooManyStreams, locking the user out of
their own playback.

When the provided PlaySessionId is unknown (or owned by another caller), fall
through to the existing CompatToken-scoped FindByRoute reuse instead of erroring,
so all of a direct play's requests share one session. Reuse stays scoped to the
caller's own token, so a guessed/foreign id cannot bind another user's session.
Adds a test asserting StartSession runs once across repeated Static requests.
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