Repository navigation
feat(api): fail readiness before an API server stops serving - #2343
Conversation
An API server that is told to stop now answers /api/v1/ready with 503 shutting_down and keeps serving for SILO_SHUTDOWN_DELAY (default 5s) before its listeners close, so load balancers and Kubernetes route new requests away first. A second signal skips the wait. Liveness is unchanged. 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 9 minutes. View limit details
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to The shutdown-readiness change is mergeable after normal checks. No actionable issue is established by the supplied evidence. Pre-merge checks |
|
Quick104
left a comment
There was a problem hiding this comment.
Adversarial review (gpt-6.1-sol, reviewed a8bb5e0)
One verified finding below. Focused package suites passed with -race: cmd/silo, internal/api, internal/api/handlers, internal/scenariocatalog, and internal/contractledger. A concurrent readiness check also passed. The finding was reproduced with the production delay helper and the shutdown select extracted from main.go; storage-admission loss was simulated. Live storage transitions and Kubernetes propagation were not exercised.
AI disclosure: gpt-6.1-sol; Codex via T3 Code.
A restart request, storage admission loss or listener failure that arrived during SILO_SHUTDOWN_DELAY stayed queued until the delay ended, so the listeners kept serving after storage writers had stopped. The wait now watches all of them and stops at once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Readiness probed PostgreSQL, S3 and artwork storage before it checked for shutdown, so a hung storage probe could hold back the shutting_down answer for up to five seconds, the whole default delay. While shutting down it now reports the last probe results instead of probing again. 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:
|
Readiness read the shutdown flag before probing, so a request whose probes spanned the signal still answered 200. It reads the flag again after probing. 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:
|
Problem
Related issue: #2320
Validation tasks: none
An API server that is told to stop closes its listeners within milliseconds, while
GET /api/v1/readykeeps answering200until the very end. A load balancer or Kubernetes therefore has no moment to route new requests to another replica first, and requests that arrive during a rolling restart fail. This change makes a stopping API server fail readiness first and keep serving for a few seconds before it shuts down.Approach
On SIGTERM or SIGINT the API process marks itself as shutting down.
/api/v1/readythen answers503with{"status":"shutting_down","postgres":…,"s3":…,"artwork":…}, the same shape as its other non-ok answers. The booleans report the last dependency probe, so the answer does not wait on a slow storage probe. The LAN discovery advertisement is withdrawn. The server keeps serving everything forSILO_SHUTDOWN_DELAY(a duration or whole seconds, default5s,0skips the wait), then runs the existing graceful shutdown. A second signal ends the wait./api/v1/health, the liveness probe, does not change, so nothing restarts the process while it waits.The application context is now cancelled after the wait instead of at the signal, so background work keeps running while the server still answers requests. A restart request still stops at once, and ends the wait if it arrives during it: an administrator's restart has already told players the server is restarting, and the loss of storage admission sends one after it has stopped storage writers. A failed listener also stops the process at once, during the wait or not.
The example compose
siloservice and proxy getstop_grace_period: 2m, since Docker's default 10-second kill already cut the existing 30-second graceful shutdown short. The development compose file andmake dev-backendset the delay to0, becauseairkills the process half a second after interrupting it.docs/architecture/api-shutdown.mddescribes the sequence and the Docker and Kubernetes settings, and the retained probe contract inapi-contract.mdrecordsshutting_downas an additive status, likedegraded.No client calls
/api/v1/ready; the Apple and Android reachability checks read/api/v1/health, which does not change. The Jellyfin-compatible and Audiobookshelf-compatible listeners have no readiness probe and close as before. Transcode nodes drain separately in #2340.Validation
200 okuntil the listener closed 5 ms after the signal, then connections were refused.503 shutting_downwithin 100 ms of the signal while health stayed200, and the graceful shutdown began 5.0 s later. A second SIGTERM one second after the first started the shutdown at once.go build,go vetandmake lint-changed(0 issues) pass, as do the tests ofinternal/api,internal/api/handlers,internal/scenariocatalog,internal/contractledgerandcmd/silo. No web or generated contract changes.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/api-shutdown-readiness/
Risks
SILO_SHUTDOWN_DELAYlonger, 5 seconds by default. A single server with no load balancer can set it to0.nodeDrainTimeoutin feat(nodes): drain transcode nodes before they stop #2340 parses its variable the same way; whichever pull request merges second can share one helper.200readiness as an outage alerts for the seconds a server spends stopping.Follow-ups
Checklist
AI Disclosure
airwould kill the dev server mid-wait, that LAN discovery kept advertising during the wait, an overflow in the seconds form, an unbounded test wait, and stale docs (grace-period sizing,blob-storage.md, listener scope). All were fixed. A background Codex (gpt-6.1-sol) review then found that a restart request, storage admission loss or listener failure arriving during the wait stayed queued until the delay ended. The wait now stops at once for each. A Kody review then found that readiness probed its dependencies before checking for shutdown, so a hung storage probe could delay theshutting_downanswer by the whole default delay; it now reports the last probe.🤖 Generated with Claude Code