Repository navigation
feat(nodes): drain transcode nodes before they stop - #2340
Conversation
A transcode node that is stopped or upgraded no longer cuts its streams. An administrator can drain a node from the admin API or the nodes page, and a node that receives SIGTERM drains on its own for up to SILO_NODE_DRAIN_TIMEOUT (default 10m). A draining node stays pooled and health-checked, takes no new transcodes, downloads, trickplay, chapter thumbnails or samples, keeps serving the sessions it runs, and reports draining, then drained, in its health answer. It announces each change so every API server rechecks it at once. Refs #2320 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:
|
|
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 13 minutes. View limit details
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 |
Quick104
left a comment
There was a problem hiding this comment.
Adversarial review (gpt-6.1-sol, reviewed 1ca013e)
Three findings reproduced with production handlers and planners in focused Go tests under -race, using existing FFmpeg stubs. The focused drain and playback race checks also passed. Database tests skipped without a configured test database; web tests and deployed playback, device, and Kubernetes validation were not run.
AI disclosure: gpt-6.1-sol, Codex via T3 Code.
A whole-seconds SILO_NODE_DRAIN_TIMEOUT beyond what time.Duration holds wrapped around; it now falls back to the default like any invalid value. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ning A node that has reported drained may be stopped at once, so it now refuses a fresh progressive remux, planning no longer keeps a session on it, and Jellyfin does not adopt the runtime recorded there. Native v3 capability planning skips draining nodes, which refuse every new transport. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… resume - A node could report drained while a rebuild or remux that had just counted itself started FFmpeg. The work check and the latch now share a lock with the admission check. - A sweep answer from before a node began draining could overwrite the recheck its announcement caused. Health checks of one node now run one at a time. - Lifting a drain request that was never set cleared the state a SIGTERM-draining node had reported, and the node announced nothing to put it back. Only lifting a set request clears it now. 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:
|
Resolves the conflicts with node draining (#2340). The sweep now publishes through ApplyHealthReport, so that clears the unreachable mark too. A recheck takes the node's check lock and publishes through the sweep's publishHealth, so it stores the drain state the node answered with and cannot overwrite a newer check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
Closes #2320
Related issue: #1176
Validation tasks: none
Stopping, upgrading or scaling down a transcode node cuts every stream on it. On SIGTERM the node closes its listener and kills FFmpeg within milliseconds, so every viewer on it stalls and only recovers through a fresh transcode elsewhere. Disabling the node first does not help: it drops the node from the pools, which also stops its health checks, so nothing tells the operator when the node is empty. This change lets a transcode node drain: it takes no new work, finishes what it runs, and says when it is safe to stop.
Approach
A node drains for one of two reasons:
POST /api/v2/admin/nodes/{id}/drainand/resumeset and clearstream_nodes.drain_requested. The web nodes page has Drain and Resume buttons and a status line:Draining · N transcodes left, thenDrained · safe to stoponce the node reports it. The request is operational state, so it does not move the node'sconfig_etag.SILO_NODE_DRAIN_TIMEOUT(default 10 minutes,0turns it off) before the existing shutdown runs. A second signal stops it at once.While draining, the node:
503 node is drainingto a new/transcode/start, which both playback retry loops already treat as "try the next node". It still accepts a start that replaces a session it runs, which is how a Jellyfin audio-track switch arrives.drainedit rebuilds no lost session and starts no fresh progressive remux, since whoever read that answer may stop it./api/v1/healthwith200andstatusdraining, thendrainedonce no session, job or work request is left.The node announces each change on the event bus (
node_drain_changed), and every API server rechecks it at once. The API stores the reported state instream_nodes.drain_state. A draining node stays pooled, so its health and GPU load keep counting. New placement, side-work reservations, native v3 capability planning and Jellyfin capability negotiation skip it. The one exception is a session that is already on the node, so a Jellyfin client asking for its master playlist again keeps its stream; once the node reportsdrained, that client is planned elsewhere. The node reads its own drain request with a one-column query of its row. That read happens on every config load and onnode_pool_changed, and it does not reload the config.Proxies do not drain. A proxy holds no session it could finish on its own, so nothing could say when stopping it is safe, and the drain operations answer
409for one. The example composesilo-transcodeservice getsstop_grace_period: 11m.docs/architecture/node-drain.mdcovers the protocol and the Docker and Kubernetes settings (terminationGracePeriodSeconds, probes). The admin API, probe contract and worker protocol docs are updated.Neither the Apple nor the Android app uses the admin nodes API, so they need no change; their playback sessions keep running on a draining node like any other client's. Failing API readiness during shutdown is #2343.
Validation
Draining · 1 transcode left, thenDrained · safe to stop(desktop and phone) once the viewer stopped. Resume put the node back to Healthy.go build,go vet,make lint-changed(0 issues), the web lint, format, build, budget and test runs, and the generated-contract checks pass. The v2 contract diff is additive.internal/mediasample's real-FFmpeg tests, which fail the same way on main with this machine's FFmpeg.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/issue-2320/
Risks
statusis nowdrainingordrainedinstead ofok; the status code stays200, and the probe contract records it as an additive revision, likedegradedon readiness. A monitor that matches the body text"ok"would alert during a drain.SILO_NODE_DRAIN_TIMEOUT, or0restores the old behavior.503sends it to another node; an older node never reportsdrained, so the page stays atDrainingfor it.draineddoes not account for prepared downloads stored on the node.CheckNode,UpdateHealthandApplyHealthkeep their signatures.Follow-ups
stream_nodesfixture and no CI run. Found in review; it predates this pull request, and its fix should add this pull request's two columns.Checklist
AI Disclosure
🤖 Generated with Claude Code