…as it started
A Jellyfin play with no stored recipe starts its first local transcode
in ensureTranscodeSessionWithToneMapMode. When its native session went
away while the start was running (a stop, an expiry or an
administrator's end, any of which found no transcode to close), the
start still published the transcode. persistTranscodeRecipe only logged
the missing session, and FFmpeg kept encoding with nothing left to
expire it. Silo-Server#4128 closed this for a rebuilt transcode.
The start now checks the session under the lifecycle lock it already
holds to publish, before writing the recipe, and closes its transcode
when the session is gone. It returns errCompatUpstreamSessionGone, which
the playlist route answers with 404 and no teardown of the play, as for
a rebuild. The transcode manager's check gets a Locked form for a
caller that holds that lock.
Closes Silo-Server#4130
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
Closes #4130
Related issue: #4120 (the rebuild half, fixed by #4128)
Validation tasks: none
Other clients: Jellyfin-compatible clients get a 404 for that one playlist request, as for a rebuild, and recover on the next one if they keep playing. Apple, Android and Roku N/A: the native API is unchanged.
A Jellyfin play with no stored recipe starts its first local transcode in
ensureTranscodeSessionWithToneMapMode. When the play's native session went away while the start was running (a stop, an expiry or an administrator's end, each of which found no transcode yet and closed nothing), the start still registered and published the transcode.persistTranscodeRecipeonly logged the missing session. If the client went away too, FFmpeg kept encoding with nothing left to expire it.This PR has no dependencies and can merge in any order. #4128, which the issue said to follow, is merged, and this PR reuses its error, 404 answer and skipped teardown.
Approach
errCompatUpstreamSessionGone. That is before the recipe write, so nothing is persisted for a gone session.TranscodeManager.CloseTranscodeSessionIfSessionGoneis split: the newCloseTranscodeSessionIfSessionGoneLockeddoes the check and close for a caller that holds the session's lifecycle lock. The rebuild keeps calling the locking form, unchanged.persistTranscodeRecipe's comment anderrCompatUpstreamSessionGone's now describe the start too.Validation
gofmt,go vetand the changed-lines lint are clean.TestTranscodeStartClosesTranscodeOfEndedSessionuses fix(jellycompat): close a transcode rebuilt for a playlist request after its play's session ended #4128'snewLostTranscodePlayfixture without a recipe, so the play takes the start branch. ThecompatLocalTranscodeReadytest hook stops the native session once the transcode is registered and before it is published. It checks that the start returnserrCompatUpstreamSessionGone, leaves no transcode registered, keeps the play, and writes no recipe.TestPlaylistRebuildClosesTranscodeOfEndedSessionandTestPlaylistRebuildKeepsTranscodeAResumedPlayAdoptedstill pass.go test ./internal/jellycompat/ ./internal/playback/passes.make test-go.Evidence
No visible change. The evidence is what a start does when its session goes away mid-start, from the test on WSL2 (Ubuntu,
go1.26.4 linux/amd64),mainat48cae66d2, this PR atd2c4c0930.mainerrCompatUpstreamSessionGone(playlist: 404)Risks
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Close first transcode in
jellycompatwhen its play session ends during startupPlaybackHandler.ensureTranscodeSessionWithToneMapModenow checks the session after registering a newly started transcode, closes it, and returnserrCompatUpstreamSessionGonebefore recording stream details or persisting the recipe.TranscodeManager.CloseTranscodeSessionIfSessionGoneLockedin transcode_manager.go so callers holding the session lifecycle lock can check-and-close atomically; it only removes the transcode if it is still the registered instance. The existing non-locked helper now delegates to it.Macroscope summarized d2c4c09.