Repository navigation
fix(jellycompat): reuse the play session for Static direct play instead of leaking one per request - #165
Conversation
…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.
|
Warning Review limit reached
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Code reviewNo 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 👎. |
…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.
Problem
Clients that direct-play via
GET /Videos/{id}/stream?…&Static=truenever callPlaybackInfo, so they send their own client-generatedPlaySessionIdand repeatit on every byte-range request.
resolvePlaybackRoutelooked that id up, missed(the server never minted it), returned
ErrSessionNotFound, andHandleVideoStreamfell to
createStaticPlaySession→ a new upstream session for every request.Each new session counts toward the per-user
max_streamscap and only ages outafter the 45s activity grace, so a single direct play's range requests pile up
orphaned sessions and quickly trip the cap →
429 TooManyStreams, locking theuser out of their own playback. (Confirmed in real traffic: one playback's
PlaySessionIdrepeated 160+ times, each request minting a fresh session.)Approach
When the provided
PlaySessionIdis unknown (or owned by another caller), fallthrough to the existing CompatToken-scoped
FindByRoutereuse instead oferroring, 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
the 45s grace still legitimately hit
max_streams(real concurrency, not aleak;
activeCountLockedhas no per-item dedup)./Videos/{id}/stream(and the subtitle path)with an unknown
PlaySessionId, not strictlyStatic=true. This is safe: theplay method is recomputed per-request from the resolved source's
direct-play/stream flags,
ensureUpstreamPlaybackrestarts the upstream sessionon a method mismatch, and reuse is CompatToken-scoped. Transcode/HLS manifest +
segment handlers resolve sessions via
playbackStore.Getdirectly and areunaffected.
Testing
TestHandleVideoStream_StaticDirectPlayReusesSessionAcrossRequestsassertsStartSessionruns exactly once across 3 repeated Static requests carrying thesame client
PlaySessionId. Mutation-verified (revert → 3 calls → RED).gofmt/go vetclean; fullinternal/jellycompatsuite green in thelibvips-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.