Repository navigation
fix(playback): end relays when a node stops sending body data - #3269
Conversation
The liveness watch in `transcodeproxy.DoNode` ended when response headers arrived. A node that hung partway through a segment body left the relay, and the viewer, waiting until the client gave up. The watch now also covers each pending body read. A read with no data after the grace period probes the node's health endpoint, and two missed probes end it with `nodepool.ErrNodeNotAnswering`. No watch runs between reads, so a slow viewer does not trigger probes. Body data clears a remembered hung node, as headers already did. The Jellyfin-compatible manifest and segment relays now use `DoNode`, so they get the same watch. The native, Jellyfin-compatible, and proxy relays log the node and playback session when a body read fails this way. The partial response cannot move to another node. On the native API, the client's next request finds the remembered hung node and moves the transcode to a healthy one. Signed-off-by: Anagh Kumar Baranwal <[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:
|
|
Visible playback behavior lacks evidence in Visible Jellyfin-compatible segment behavior lacks evidence in Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
Caution Review failedThe pull request is closed. No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Watch pending body reads internal/transcodeproxy/liveness.go, internal/transcodeproxy/liveness_test.go |
DoNode wraps response bodies and watches each pending read. A hung read returns an error classified as ErrNodeNotAnswering. Body data or a successful health probe clears remembered hung state. Tests cover stalled reads, slow live responses, probe timing, and recovery. |
Apply liveness monitoring and abort incomplete relays internal/jellycompat/streams.go, internal/jellycompat/remote_relay_transport_test.go, internal/api/handlers/playback.go, internal/api/handlers/playback_hung_node_test.go, internal/api/handlers/playback_proxy_test.go, internal/proxy/server.go, internal/proxy/segment_completion_test.go |
Jellyfin-compatible manifest and segment relays use DoNode. Native, proxy, and Jellyfin-compatible relays abort active responses when body copying fails. Playback tests cover header and body freezes, partial responses, retry, and failover. |
Document probe and playback behavior docs/architecture/node-failure-detection.md, docs/architecture/restart-resilient-playback.md |
The architecture documentation describes probe timing, body-read monitoring, relay failure behavior, client retry, and calls that remain unwatched. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant PlaybackClient
participant PlaybackRelay
participant transcodeproxy.DoNode
participant TranscodeNode
participant watchedBody
PlaybackClient->>PlaybackRelay: Request playback data
PlaybackRelay->>transcodeproxy.DoNode: Send node request
transcodeproxy.DoNode->>TranscodeNode: Forward request
TranscodeNode-->>transcodeproxy.DoNode: Return response headers and body
transcodeproxy.DoNode-->>PlaybackRelay: Return watched response
PlaybackRelay->>watchedBody: Copy response body
watchedBody-->>PlaybackRelay: Return body data or read error
PlaybackRelay-->>PlaybackClient: Send data or abort incomplete response
Possibly related issues
- Silo-Server/silo-server#1176 — The change detects a stopped transcode node during a body read and ends the stalled relay, allowing a later client request to retry. Failover itself is not shown as complete.
Possibly related PRs
- Silo-Server/silo-server#2579 — This PR extends that PR’s header liveness watch to pending body reads.
- Silo-Server/silo-server#2350 — This PR routes Jellyfin-compatible relays through
DoNodeso body-read liveness failures use the existing retry and move path. - Silo-Server/silo-server#2355 — This PR relies on the existing node-move and transport-release path for a later playback request.
Suggested reviewers: rhainland, quick104
Merge Risk: 
Minimal · up to b33a1
-
No merge-blocking risk is established by the supplied evidence.
Security architecture risk: 
Low · up to b33a1
-
The change improves containment of stalled playback without changing the inspected access checks or who selects playback destinations. Recovery still depends on another client request, and compatibility-client migration remains outside this change. Deployment-level behavior has not been validated.
Retained concerns
No architecture-level concerns identified.Security review details
-
Security Blast Radius
- inferred — Liveness effects are shared across requests to the same normalized node within a serving process, rather than isolated to one playback session. A remembered failure accelerates probing for other sessions on that node, but does not itself grant destination-selection or session-access authority.
Trust Boundaries and Controls
- observed — The inspected native relay remains downstream of session ownership and API-egress checks. It signs the selected node request and forwards a reconstruction token only after verification and a matching session ID. The changed copy-error branch does not select a replacement destination.
- observed — Jellyfin-compatible callers require an authenticated context and a playback session bound to that compatibility token. They derive remote destinations from the session recipe and sign requests. The dedicated proxy likewise uses the node named in its claims and signs the outbound request; the PR retains these controls in the inspected relay blocks.
- observed — Health probes use a separate connection pool, refuse redirects, and target the selected node's health endpoint without copying playback credentials. An HTTP answer establishes process responsiveness, not authorization or application health.
Resilience and Maintainability Implications
- observed — Finishing an operation signals its watcher and stops its grace timer; closing the wrapped body cancels the request context. Shared probes have their own bounded lifetime, so cancellation by one viewer does not cancel the probe used by other requests.
- observed — A committed response is not moved between executors. The documented recovery contract requires a subsequent native API request to trigger rehome; proxy playback requires client replanning, while Jellyfin-compatible playback still requires retry or replanning rather than gaining automatic migration here.
-
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 7 files. (2 skipped: 2 unsupported.)
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
Please add before-and-after evidence of playback when a transcode node stops sending body data after headers: show the previous stall and the new response termination/client retry, naming the client surface and builds. The Evidence section says nothing was captured; the reported relay-test timings do not show the user-visible playback behavior. Include the Jellyfin relay behavior or state its remaining recovery limitation alongside the capture. |
|
No playback capture for this one. The change only affects a node that hangs mid-response, and reproducing that on a real deployment means freezing a transcode node process during playback. The behavior is covered by tests instead:
The client sees a frozen stream end in seconds rather than staying frozen. What happens next depends on the client's retry, which this PR does not change. |
When the body copy from a transcode node failed, the relay handler returned normally. net/http then closed the chunked response cleanly, so a player could take a stalled progressive remux as the end of the movie. The native API, proxy, and Jellyfin-compatible relays now abort the response with panic(http.ErrAbortHandler) when io.Copy fails and the viewer's request is still live. This covers the hung-body error nodepool.ErrNodeNotAnswering and any other copy failure. The client sees a broken connection, not a short body that looks complete. A canceled viewer request still returns quietly. The hung-node test now serves a chunked body larger than net/http's 4 KiB response buffer and requires a client read error. The direct relay tests expect the abort. The node failure and restart-resilient playback docs describe the abort. Signed-off-by: Anagh Kumar Baranwal <[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:
|
|
The new relay-abort handling changes the visible result from a clean short-body end to an interrupted transfer, but the Evidence section still contains only test timing. For the native API/proxy playback and Jellyfin segment surfaces, add before-and-after recordings of the same stalled-body playback showing this distinction and name each surface and capture commit. The earlier reply explains why real-device captures were unavailable; this request is for the additional client-visible behavior introduced by the abort change. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
No recording for the abort change either. I have no deployment with a separate transcode node, so I cannot stall a node mid-body under a real player on any of the three surfaces. The hung-node relay test shows the client-visible change. Its body phase serves a chunked partial response from a node that then stops answering. Before b33a144 the client read status 200 and the partial body with a clean end, so it would accept the body as complete. With b33a144 the client gets the same partial body followed by a read error. The direct relay tests for the proxy and Jellyfin segment paths check for the same abort. |
|
🤖 Claude Code in T3 Code (claude-opus-5-5) Review summaryReviewed head: b33a144 Fit: 9/10 · Readiness: 8/10 — conditional (assuming CI is green) Findings
No other defects turned up. I traced Tests that fail on the base
Left for maintainers
Validated features: #1177 C3 (remove an active worker during playback) has not been run yet, so this PR can't regress a passed case. It is the case to walk once this merges. User manual: the transcode nodes guide doesn't describe hung-node behavior. Silo-Server/siloserver.org#162, which is open, already asks the guide to say what happens when a node goes away. It can cover this: a stream on a node that stops answering now fails within seconds instead of freezing, and native clients recover on retry. No new docs issue is needed. Apple/Android parity: server-only. No API or wire change. Both clients already treat a failed transfer as retryable. Why these scores: Fit 9: Silo treats a node dying mid-stream as a normal event, and this closes the gap #2579 left after headers, inside the existing liveness watch, with no new setting. Readiness 8: tests that fail on the base prove the behavior, and the code holds up under review. The open evidence decision keeps it at conditional. |
Problem
Related issue: #1176
Validation tasks: changes #1177 C3
When a transcode node hangs after it has started a response, playback freezes
and nothing recovers it. The node's process is stopped or deadlocked, but its
kernel keeps the connection open, so the server keeps waiting for the next
segment bytes. The viewer sees a frozen picture until their client gives up,
and the server logs nothing that names the node.
#2579 handles a node that hangs before it sends response headers. This change
covers the same failure after the headers: the server now notices the stalled
body read, aborts that response, and logs which node stopped answering. The
client's next request then takes the existing recovery path and moves the
transcode to a healthy node.
Approach
transcodeproxy.DoNodealready probes a node's health endpoint while a callwaits for headers. It now does the same while a body read is waiting. A node
that misses its probes is treated as hung: the read fails with
nodepool.ErrNodeNotAnswering, and the relay aborts the partial response.It aborts on any body copy error while the viewer's request is live, so a
chunked response such as a progressive remux breaks instead of ending cleanly
and looking complete. A
node that is slow but still answers its probes keeps streaming, so there is
still no fixed body deadline. No probe runs between reads, so a slow viewer
does not cause probes. Body data counts as an answer, the same way headers do,
so a node that was marked hung but is sending again is cleared.
The two native relays (the API playback relay and the proxy relay) log a
warning with the node and playback session when this happens. A cancelled
viewer request logs nothing. The Jellyfin-compatible manifest fetch and segment
relay switch from
telemetry.DoTrustedNodetotranscodeproxy.DoNode, soJellyfin clients get the same detection and warning. Moving a Jellyfin
playback to another node is still #2297. The Jellyfin-compatible
transcode start still uses
telemetry.DoTrustedNode, anddocs/architecture/node-failure-detection.mdlists it as a known gap. Movinga stream to another node while it is mid-response is out of scope; recovery
starts with the client's retry.
No API or wire format changes. Recovery depends on the client asking again.
From reading the client code (not tested on devices): Android's player retries
a short response in place for up to 90 s, then reopens and replans. On Apple
the request goes through the engine's local relay, and AVPlayer gets either a
502 or a short body. AVPlayer's retry is not under app control, but a failed
item leads the app to replan away from the failed route.
Validation
go vetandmake test-goon Linux: pass.-raceontranscodeproxy,jellycompat,proxy, andapi/handlers: pass.make lint-changed: 0 issues.make verify-local-paths: pass.and passes with the fix (about 8 s). The Jellyfin segment relay test and the
body-watch unit tests also fail on the old code and pass with the fix.
verify-*targets: not run. There are no web orcontract changes.
Evidence
Evidence: none captured. The change affects only a hung-node failure path. The
hung-node relay test covers it: the stream froze for the full 45 s before the
fix and ends after about 8 s with it.
Risks
Each body read on a transcode node now starts a short timer. A local benchmark
put the cost at about 0.23 microseconds per read. While a node is remembered as
hung, the first read on it probes at once. One missed probe is then enough to
end the read, as it already was for header waits.
Checklist
AI Disclosure
codex execNote
End relays when a transcode node stops sending body data
DoNode's liveness watch to cover each pending body read, not just the response-header wait. A stalled read is canceled with an error wrappingErrNodeNotAnsweringafter missed probes, and body data clears the remembered-hung mark (liveness.go)PlaybackHandler.relayToTranscodeNode), proxy relay (Server.proxyToTranscodeNode), and Jellyfin-compatible segment relay (PlaybackHandler.proxyRemoteCompatSegment) now panic withhttp.ErrAbortHandlerinstead of ending the response as a short bodytranscodeproxy.DoNodeso header waits and body reads are both watchedErrNodeNotAnsweringbody failures also log a warning with the node and session IDMacroscope summarized b33a144.