Repository navigation
fix(jellycompat): close a transcode that was starting when a Jellyfin client stopped playback - #4119
Conversation
… client stopped playback A start or rebuild holds the session lifecycle lock from before it starts FFmpeg until it has registered the transcode. The Jellyfin stop closed the transcode without that lock, so a stop that arrived in between closed nothing, and the start then registered a transcode for a play that had ended. A transcode rebuilt for a playlist request stayed running, with no session left to expire it. The stop still closes what is registered at once. After finishing the session it now takes the lifecycle lock on every stop and closes the local transcode again, before the recipe delete it already did under that lock. Closes #4112 Co-Authored-By: Claude Fable 5.2 <[email protected]>
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 Summary: ✅ CompletedThis 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. |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ecycle lock now that restart hooks time out Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
Review summaryReviewed head: 045e598. I merged current Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green) Fit. This fixes a real resource leak on the Jellyfin surface: FFmpeg keeps encoding for a play that has ended. It fixes it at the stop, with a small change that brings the Jellyfin stop in line with the native stop, which already takes the session lifecycle lock before it closes. It complements #4128 and doesn't duplicate it. #4128's check runs after a rebuild registers, and a stop that removes the session only after its own close lets that check pass. #4128's description names this case as left to this PR. Readiness. The diff introduces no defect. Addressed
Checked and not a problem in this diff
For the maintainers (present on
|
Problem
Closes #4112
Related issue: N/A
Validation tasks: none
Other clients: N/A (no client-visible change)
When a Jellyfin client stops playback while the server is starting or rebuilding that play's transcode, the stop finds no transcode to close, and the start then registers one for a play that has ended. FFmpeg keeps encoding with nobody watching. With this change the stop waits for a start in flight and closes what it registered.
A start or rebuild holds the session lifecycle lock from before it starts FFmpeg until the transcode is registered. The Jellyfin stop closed the transcode without that lock. On
mainthe transcode that stays is one rebuilt for a playlist request. Since #4128 that rebuild checks the native session after it registers, but the stop removes the session only after its close, so a rebuild that registers between the two still passes the check, and with the session gone no expiry reaches it. A rebuild for a segment request already closes itself when it finds the session gone, and a fresh start is closed when it fails to store its recipe, after its manifest wait.Approach
cleanupPlaySessionkeeps its immediate close and the session finish. It then takes the lifecycle lock on every stop and closes the local transcode again, before the recipe delete it already did under that lock. The native stop already takes the lock before it closes.The shipped server always has a recipe store, so a Jellyfin stop already waited on this lock. The new part is the close under it.
The first close stays outside the lock because a segment or seek restart holds the lock through its restart hook, and that hook can wait on the FFmpeg context that only a close cancels.
Not covered here, and present on
main: a fresh start that takes the lock only after the stop has finished, which #4130 tracks. Its publish step closes it once its manifest wait ends. A playlist rebuild in that position closes itself since #4128.Validation
internal/jellycompattests pass under the race detector, andmake lint-changedreports 0 issues.TestCopyRemuxSubtitleRenditionRealFFmpegandTestRunStatsWithRealFFmpeg. They are ininternal/playbackandinternal/mediasample, which this change does not touch or reach, and they fail on FFmpeg 6.1.1 without it. The web gate was not run; no web file changes.main(with fix(playback): don't hold a playback stop behind a transcode restart's stalled settings read #4127 and fix(jellycompat): close a transcode rebuilt for a playlist request after its play's session ended #4128), the test still fails onmainat 91611b4 and passes on the head under the race detector, as do the rest of theinternal/jellycompattests.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/issue-4112/
Risks
A stop that overlaps a start returns once the start has registered, which for a rebuild that waits on its first manifest can take up to the 30-second startup wait per attempt. The shipped server already waited there.
If a restart's hook stalls while it holds the lock, for example on a hung settings read, the stop waits behind it, for at most 5 seconds since #4127. A rebuild's first throttler start also runs under the lock with no time limit; open PR #4121 would bound it.
Checklist
AI Disclosure
go test)mainhas the same wait, so the plan stayed, and Sol's alternative, a stop fence in the transcode manager, is larger than this bug needs. A code review at high effort (claude-fable-5-2 and claude-sonnet-5-5 finders, one verifier) found no defect the diff introduces and confirmed the two gaps listed under Approach as present onmain. A simplify pass kept the recipe delete's error handling as it was. A background adversarial review by gpt-6.1-sol of 73e2cb6 found no defect in this diff and posted nothing; it listed the same gaps as present onmain, since fixed by fix(jellycompat): close a transcode rebuilt for a playlist request after its play's session ended #4128 and fix(playback): don't hold a playback stop behind a transcode restart's stalled settings read #4127. A maintainer review by claude-opus-5-5 merged currentmain, ran code-review finders and a gpt-6.1-sol round on the merged head, found no defect the diff introduces, and corrected one code comment.🤖 Generated with Claude Code
Note
Close transcodes that start while a Jellyfin stop request is in progress
PlaybackHandler.cleanupPlaySession: a client can start a new transcode while a stopped-playback request waits on the session lifecycle lock, and that transcode was left openMacroscope summarized 045e598.