You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(playback): don't hold a playback stop behind a transcode restart's stalled settings read - #4127
Closes#4122
Related issue: N/A
Validation tasks: none
Other clients: N/A (no client-visible change)
When the database stalled during a transcode restart (a seek, an audio switch, or a segment recovery), a playback stop for the same session waited for as long as the stall lasted, and FFmpeg kept running after the viewer had stopped. With this change the restart gives up on its settings read after five seconds, so the stop goes through and ends FFmpeg.
A restart runs its restart hook while it holds the session lifecycle lock. The hook reads the transcode throttle settings with the new FFmpeg process's context, which only a close cancels. Every stop takes the lifecycle lock before it closes the session, so the stop could not be the close that freed the hook. The settings read is an uncached database query, and the pool sets no acquire or statement timeout.
Approach
restart now gives the restart hook a context that also ends after restartHookTimeout, and logs a warning when the hook runs out of time. The timeout is five seconds, the bound #4121 uses for a transcode's first throttler start. The FFmpeg process keeps its own context, so a close still cancels the hook at once and shutdown behaves as before.
A restart stops the session's throttler and relies on the hook to start a new one. When the hook times out before it has, the restart starts a throttler with the threshold the session had before the restart, so a slow database does not turn the throttle off.
The bound sits where restart calls the hook, so it covers the native, Jellyfin-compatible, and rebuilt-session hooks on the API server. The transcode node's hook reads no settings and ignores its context.
Letting a stop close the session before it takes the lifecycle lock would remove the wait entirely, as #2524 did for shutdown. I left that out: the native stops take the lock first so that they wait for a session replacement to commit, and they can still fail without ending anything. It would also change four stop paths, one of them the lines #4119 changes.
No API, client, or Jellyfin wire change.
Validation
Not reproduced on a deployment, because a test deployment cannot stall the settings store on demand. Reproduced with tests that run the real transcode manager and a stand-in FFmpeg process.
An end-to-end reproduction wires the throttler start as the playback handlers do, over a settings store that never answers. It is not in this pull request because it waits on the real timeout. On the unfixed base, after 15 seconds the restart still held the lock, the stop was still waiting, and FFmpeg was still running. With the fix the restart returned after 5 seconds with FFmpeg running, and a stop queued behind it returned with FFmpeg closed.
The added test stalls the restart hook of a throttled session and requires a stop to get the lock while FFmpeg is still running and still throttled at its earlier threshold, then close it. It fails on the unfixed code, where the stop never gets the lock, and on this pull request's first commit, which lost the throttle. It passes on the head, 10 runs out of 10 under the race detector. It shortens the new timeout variable, so its failing run on the unfixed code used the base plus that one declaration, which nothing on the base reads.
The existing shutdown test now sets the timeout to an hour, so it still fails if shutdown waits on a hook.
Go gate, run in full on the first commit and repeated for the playback, transcode node, handler, and Jellyfin-compatible packages on the head: build, gofmt, go mod tidy -diff, go vet, make lint-changed, and make lint-router-recovery pass. make test-go passes except two tests that drive the host's FFmpeg 6.1.1 (subtitle rendition seek and media sample stats); both fail the same way on the unfixed base.
The contract and hygiene targets pass: settings bindings, playback fixtures, route inventory, the /api/v2 OpenAPI, web types, contract, and fixtures checks, local paths, case collisions, size ratchet, bidi, and migrations.
Not run: the web lint, build, budget, and test targets, verify-actionlint, verify-shellcheck, and verify-prometheus-rules. The change touches no web file, workflow, shell script, or alert rule.
Evidence
Nothing a user sees changes. The evidence page has the reproduction, its runs on the unfixed base and on the fix, and the added test's failing run.
A settings read that takes longer than five seconds during a restart no longer applies the current settings to that FFmpeg process. It keeps the threshold the session had before the restart, so a change an administrator made since then waits for the next restart, and a session that had no throttler stays without one. If only the second of the two reads times out, the throttle runs at the default threshold instead of the configured one. Before, the restart waited for the database and then read the settings. The warning log records the timeout with the session ID.
A stop still waits up to five seconds behind a stalled restart hook, and that long again for each further restart queued for the session ahead of it. As before, a restart also holds the lock across its tone-map source check, which is bounded at 20 seconds.
Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
The Evidence section shows every change a user can see, or how I checked a change nobody sees.
AI Disclosure
Harness: Claude Code (T3 Code)
Tool(s): git, GitHub CLI, Go toolchain (go build, go test, go vet), golangci-lint through make lint-changed, T3 Code delegated review tasks, Codex
Model(s): claude-fable-5-2 (implementation and review), claude-opus-5-5 and gpt-6.1-sol (plan review), claude-sonnet-5-5 (review agents)
Involvement: Fully AI-generated (not yet human verified)
Adversarial review: Before implementation, gpt-6.1-sol attacked the plan and reported that it holds, with no findings; it reran the lock cycle on the unfixed base, and its caveats led to the test's check that FFmpeg is still running when the stop gets the lock. claude-opus-5-5 found the plan already minimal and narrowed the warning's condition. A multi-agent code review of the diff at high (claude-fable-5-2 and claude-sonnet-5-5 finders, a verifier, and a validation check) found no defect in the fix. It replaced a first test that only checked the hook's context had a deadline, corrected the warning's wording, and confirmed the throttle trade-off, which an automated review of this pull request then raised as well; the second commit keeps the session's earlier threshold in answer to both. A simplify pass changed nothing. The background adversarial review by gpt-6.1-sol reviewed the first commit (93013d3) and reported no findings, so it posted nothing. The two commits after it are this run's own: the second got another code review pass (claude-fable-5-2 and claude-sonnet-5-5 finders), which found no defect and led to the third, a refactor with no behavior change.
Fix playback stop getting blocked by a stalled transcode restart hook
A transcode restart hook could block indefinitely on a settings read, holding up a playback stop. In transcode.go:
TranscodeSession.restart now calls the restart hook with a context bounded by a new five-second restartHookTimeout, and cancels it after the hook returns.
StopThrottler now returns the stopped throttler's threshold; if a hook returns after its deadline without installing a throttler, restart restores the previous throttle threshold and logs a warning.
The hook call stays synchronous, so restart still does not return while a hook is blocked — the timeout only protects the stop path.
…s stalled settings read
A restart runs its restart hook under the session lifecycle lock, with the
new FFmpeg process's context, which only a close cancels. A stop takes that
lock before it closes the session, so while the hook's throttle settings read
waited on a stalled database, the stop waited too and FFmpeg kept running.
Give the hook a context that also ends after five seconds, and log a warning
when it does. The restart then returns, the stop takes the lock, and the
close ends FFmpeg. A hook that times out leaves that FFmpeg process's
throttle off, or at the default threshold, until its next restart.
Closes#4122
Co-Authored-By: Claude Fable 5.2 <[email protected]>
No actionable comments were generated in the recent review.
Walkthrough
Restart hooks now run with a five-second timeout context. If a hook times out before starting a throttler, the restart restores the previous throttler threshold. Tests cover stalled hooks, throttler preservation, and session shutdown.
The SetRestartHook documentation describes the callback context lifetime and requires blocking callback work to honor the context. A five-second timeout is defined for restart hooks.
Hook timeout execution and validation internal/playback/transcode.go, internal/playback/transcode_manager_test.go
The restart path saves the throttler threshold before stopping the throttler. It runs the hook with a timeout context and restores the threshold if the hook times out without starting a throttler. Tests cover a stalled hook, throttle preservation, and session-close cleanup.
Restart hooks no longer hold the session lifecycle lock indefinitely, and the previous throttle setting is kept when the hook times out. One minor, pre-existing throttler-overlap race remains and is tracked in a follow-up issue; it is bounded and does not block merging.
Security architecture risk: Minimal · up to bc316
The timeout improves stop responsiveness while preserving process shutdown and throttling controls. The inspected change establishes no introduced or worsened security or failure-containment risk.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The changed transition operates on the existing session's process context and throttler threshold. The lifecycle lock is keyed by session ID, and the manager checks that the requested session object is still the live mapped instance before restarting it. The change does not broaden session identity or process ownership.
Trust Boundaries and Controls
observed — The hook timeout does not cancel FFmpeg's parent context. Close marks the session terminal and cancels the process context, which also cancels the hook. StartThrottler refuses to arm while closing, so timeout recovery cannot intentionally revive throttling after terminal shutdown begins.
Resilience and Maintainability Implications
observed — Restart and the inspected stop path retain the same per-session lifecycle gate. The hook is called synchronously, so cancellation cooperation remains required. Added test source checks that a deadline-responsive stalled hook releases a waiting stop, preserves the prior 120-second threshold, and does not terminate the replacement process; shutdown cancellation is also covered in the inspected test source.
observed — Recovery favors continuity over immediately refreshed throttle settings: deadline fallback restores the previous threshold only when no throttler exists. If the enabled setting succeeds but the threshold read fails, the existing settings resolver can install its default instead, preventing fallback. The timeout warning explicitly acknowledges temporary settings divergence.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names a real and central change: a playback stop should not wait behind a transcode restart's stalled settings read. The changeset adds a five-second timeout to the restart hook context and …
Description check
The description explains the problem, the approach (a five-second restart hook timeout, threshold restoration on timeout, a warning log), the validation and tests, and the risks. It relates directly t…
Linked Issues check
Issue #4122 asks that a playback stop end the transcode without waiting on a restart's stalled throttle-settings read. It allows either bounding the read or letting a stop cancel FFmpeg without the li…
Out of Scope Changes check
The whole-PR change set stays within the restart timeout path in internal/playback/transcode.go and its tests. It includes the SetRestartHook doc comment, the restartHookTimeout variable, the hookCtx …
Full details: Title check
Explanation
The title names a real and central change: a playback stop should not wait behind a transcode restart's stalled settings read. The changeset adds a five-second timeout to the restart hook context and a throttle-threshold fallback, which the title captures. The title is concise and specific, though its wording is somewhat long at 92 characters.
Full details: Description check
Explanation
The description explains the problem, the approach (a five-second restart hook timeout, threshold restoration on timeout, a warning log), the validation and tests, and the risks. It relates directly to the changeset.
Full details: Linked Issues check
Explanation
Issue #4122 asks that a playback stop end the transcode without waiting on a restart's stalled throttle-settings read. It allows either bounding the read or letting a stop cancel FFmpeg without the lifecycle lock. At head bc3167f, the whole-PR diff against merge base b6b7dd3 in internal/playback/transcode.go bounds the hook. restart() now passes hookCtx := context.WithTimeout(ctx, restartHookTimeout) to the hook, with restartHookTimeout = 5s. The FFmpeg process keeps its own context, so a close still cancels the hook at once. A stop queued behind a stalled restart therefore acquires the lock after about five seconds. The head adds no new settings read. Changes since the prior review (3df26d5 to bc3167f) add a warning, a StopThrottler return value, and a fallback StartThrottler call. These do not change the requirement outcome. The stop paths are unchanged, which the issue allows. Limits: the bound depends on the API and Jellyfin hooks passing their context to the settings read. I did not inspect those callers, and the inspection budget ran out before I could read the test file in full. The added test is taken from the PR description and the prior review, not from direct source read in this pass.
Full details: Out of Scope Changes check
Explanation
The whole-PR change set stays within the restart timeout path in internal/playback/transcode.go and its tests. It includes the SetRestartHook doc comment, the restartHookTimeout variable, the hookCtx wrapper, the deadline warning, the StopThrottler change that returns the prior threshold, and the fallback StartThrottler(previousThrottleSeconds) call when the hook times out with no throttler installed. Each change connects to #4122: the fallback keeps throttling after a timed-out hook, and the PR description names it as a trade-off. No API, client, Jellyfin wire, web, workflow, or alert change appears in the reviewed material. Unresolved: the source of StartThrottler was not readable within the inspection budget. When no throttler ran, previousThrottleSeconds is 0. Whether StartThrottler(0) starts a zero-threshold throttler or does nothing is unknown. The PR description's Risks section says a session with no throttler stays without one, which holds only if StartThrottler(0) does nothing. This does not make the change out of scope, but the behavior is unverified.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 21555608-494d-4159-9b6b-e8efb1148fab
Commits
Reviewing files that changed from the base of the PR and between 3df26d5 and bc3167f.
Files selected for processing: 1
internal/playback/transcode.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
…s out
A restart stops the session's throttler and relies on the restart hook to
start a new one. When the hook's settings read ran out of time, the new
FFmpeg process was left without a throttle until its next restart, even
after the database recovered.
When the hook times out without starting a throttler, start one with the
threshold the session had before the restart.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: c4e9877a-6ef7-448a-b220-dd0c151c08b6
Commits
Reviewing files that changed from the base of the PR and between 93013d3 and 3df26d5.
Files selected for processing: 2
internal/playback/transcode.go
internal/playback/transcode_manager_test.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
…meline wait
main's restart now keeps the stopped throttler's threshold for a restart
hook that times out (Silo-Server#4127). The planned restart still lets the run it
replaces set the session's timeline before stopping it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugSomething isn't workinggoPull requests that update go codeimpact: playbackCan't play, stalls, or wrong mediapriority: P2Limited scope, workaround exists, or polishsize/M50–199 added + deleted lines (all files); change volume, not priority.
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #4122
Related issue: N/A
Validation tasks: none
Other clients: N/A (no client-visible change)
When the database stalled during a transcode restart (a seek, an audio switch, or a segment recovery), a playback stop for the same session waited for as long as the stall lasted, and FFmpeg kept running after the viewer had stopped. With this change the restart gives up on its settings read after five seconds, so the stop goes through and ends FFmpeg.
A restart runs its restart hook while it holds the session lifecycle lock. The hook reads the transcode throttle settings with the new FFmpeg process's context, which only a close cancels. Every stop takes the lifecycle lock before it closes the session, so the stop could not be the close that freed the hook. The settings read is an uncached database query, and the pool sets no acquire or statement timeout.
Approach
restartnow gives the restart hook a context that also ends afterrestartHookTimeout, and logs a warning when the hook runs out of time. The timeout is five seconds, the bound #4121 uses for a transcode's first throttler start. The FFmpeg process keeps its own context, so a close still cancels the hook at once and shutdown behaves as before.A restart stops the session's throttler and relies on the hook to start a new one. When the hook times out before it has, the restart starts a throttler with the threshold the session had before the restart, so a slow database does not turn the throttle off.
The bound sits where
restartcalls the hook, so it covers the native, Jellyfin-compatible, and rebuilt-session hooks on the API server. The transcode node's hook reads no settings and ignores its context.Letting a stop close the session before it takes the lifecycle lock would remove the wait entirely, as #2524 did for shutdown. I left that out: the native stops take the lock first so that they wait for a session replacement to commit, and they can still fail without ending anything. It would also change four stop paths, one of them the lines #4119 changes.
No API, client, or Jellyfin wire change.
Validation
gofmt,go mod tidy -diff,go vet,make lint-changed, andmake lint-router-recoverypass.make test-gopasses except two tests that drive the host's FFmpeg 6.1.1 (subtitle rendition seek and media sample stats); both fail the same way on the unfixed base./api/v2OpenAPI, web types, contract, and fixtures checks, local paths, case collisions, size ratchet, bidi, and migrations.verify-actionlint,verify-shellcheck, andverify-prometheus-rules. The change touches no web file, workflow, shell script, or alert rule.Evidence
Nothing a user sees changes. The evidence page has the reproduction, its runs on the unfixed base and on the fix, and the added test's failing run.
Evidence: https://evidence.siloserver.org/r/silo-server/issue-4122/
Risks
Checklist
AI Disclosure
go build,go test,go vet), golangci-lint throughmake lint-changed, T3 Code delegated review tasks, Codexhigh(claude-fable-5-2 and claude-sonnet-5-5 finders, a verifier, and a validation check) found no defect in the fix. It replaced a first test that only checked the hook's context had a deadline, corrected the warning's wording, and confirmed the throttle trade-off, which an automated review of this pull request then raised as well; the second commit keeps the session's earlier threshold in answer to both. A simplify pass changed nothing. The background adversarial review by gpt-6.1-sol reviewed the first commit (93013d3) and reported no findings, so it posted nothing. The two commits after it are this run's own: the second got another code review pass (claude-fable-5-2 and claude-sonnet-5-5 finders), which found no defect and led to the third, a refactor with no behavior change.🤖 Generated with Claude Code
Note
Fix playback stop getting blocked by a stalled transcode restart hook
A transcode restart hook could block indefinitely on a settings read, holding up a playback stop. In transcode.go:
TranscodeSession.restartnow calls the restart hook with a context bounded by a new five-secondrestartHookTimeout, and cancels it after the hook returns.StopThrottlernow returns the stopped throttler's threshold; if a hook returns after its deadline without installing a throttler, restart restores the previous throttle threshold and logs a warning.Macroscope summarized bc3167f.