Repository navigation
Conversation
sendCompatResumeStart holds the per-session scrobble lock across the watch-provider call, so client reports queue behind it. The lock was a sync.Mutex, which lets a position-less Stopped report that reaches the lock just as the start releases it take the lock ahead of a progress report already waiting. The stop is then staged from the earlier position and providers get the wrong resume point. TestHandlePlaybackPositionlessStoppedUsesQueuedReportPosition failed intermittently (11-49% of runs locally) mostly for a test-side reason: the old lock counted a caller as queued before it waited on the mutex, so the test could not reliably set up the queue order. Handing the lock to waiters in the order they reached it fixes both, because a caller now counts as queued exactly when it joins the queue. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The FIFO lock's unlock closure was not idempotent. A second call with no waiters deleted the map entry even if a newer caller had since taken the lock, so a third caller could get in beside that owner. sync.Mutex panicked in this case; the closure now does the same. No current caller releases twice. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Warning Review limit reachedYou'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 21 minutes. View limit detailsLimit details: You’ve used all 4 included reviews currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (2)
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 |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
fix(jellycompat): serve scrobble lock waiters in arrival order (revamp copy of #1886)
|
Silo's pull request guidance changed today (#2016). A PR that changes what a user sees now needs before-and-after evidence in its Evidence section, and a PR with no visible change says Missing here: Needs the line 'Evidence: none, no user-visible change'. The rules are in Show visible changes, and the PR template shows the Evidence section layout. I've converted this PR to draft for now. Mark it ready for review once the Evidence section is filled in. Generated by Claude Code |
Problem
Related issue: N/A
Validation tasks: none
A Jellyfin client can send a progress report and then a Stopped report without
PositionTicks. If both reports wait on the play session's scrobble lock, the stop can reach watch providers with the position from before the progress report. This change gives the lock to waiting reports in the order they reached it.sendCompatResumeStartholds the per-session lock while it calls the watch provider, so reports queue behind it. The lock was async.Mutex. If a Stopped report reaches the lock just as the start releases it, the mutex can let the stop take the lock ahead of a progress report that is already waiting. The stop is then staged at the earlier position, and the progress report finds the play ended and sends nothing. The window is narrow: the Stopped report has to arrive within microseconds of the release, or the two requests have to arrive almost together.TestHandlePlaybackPositionlessStoppedUsesQueuedReportPositionfailed in 33 to 148 of 300 runs onmain, depending on machine load. Most of those failures came from the test, not from this race. The old lock counted a caller as queued before the caller waited on the mutex, so the test's "queued" signal fired too early and the test could not reliably set up the queue order. With a 5 ms pause after each signal, the old lock passed 300 of 300. The new lock fixes both problems because a caller counts as queued exactly when it joins the queue.Approach
The lock now keeps a queue of waiting callers for each session key. Unlock gives ownership to the oldest waiter. The map entry is removed when nobody holds or waits for the lock. Callers keep the same
lock(key) (unlock func())interface, so the start, report, and stop paths do not change.Releasing the same lock twice now panics, as
sync.Mutexdid. Without that check, a second release could delete an entry that a newer caller owned and let a third caller in beside it.New tests:
Validation
-count=500: 500 passed, 0 failed.-count=500: 500 passed each.-race -count=100: pass.go test -race ./internal/jellycompat/: pass.go vetandgofmt: clean.make lint-changed BASE_REF=origin/main: 0 issues.Risks
The lock still covers one session on one node. Callers still cannot cancel a wait once queued, as with the mutex. Ordering follows when callers reach the lock, not when their HTTP requests arrived, so two reports that race in the network can still be served in either order.
Checklist
AI Disclosure
-raceon the package with no failures. It found that the CI flake came mostly from the test's early "queued" signal and that the production race is real but narrow. It also found that a double release could break mutual exclusion silently; this pull request now panics in that case.🤖 Generated with Claude Code
Note
Fix jellycompat scrobble lock to serve waiters in arrival order
compatScrobbleLockswith a FIFO queue of waiter channels, so queued callers acquire the lock in arrival order instead of being overtaken by newly arriving callersMacroscope summarized fd791e0.