Add graceful shutdown with readiness drain and chart termination grace period#90
Merged
Conversation
Co-Authored-By: Şahin Olut <olut.sahin@gmail.com>
Co-Authored-By: Şahin Olut <olut.sahin@gmail.com>
Co-Authored-By: Şahin Olut <olut.sahin@gmail.com>
Co-Authored-By: Şahin Olut <olut.sahin@gmail.com>
Co-Authored-By: Şahin Olut <olut.sahin@gmail.com>
…ace period Co-Authored-By: Şahin Olut <olut.sahin@gmail.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
⚙️ Control Options:
|
Co-Authored-By: Şahin Olut <olut.sahin@gmail.com>
devin-ai-integration
Bot
changed the base branch from
devin/1781161705-helm-chart
to
main
June 11, 2026 18:36
Co-Authored-By: Şahin Olut <olut.sahin@gmail.com>
Co-Authored-By: Şahin Olut <olut.sahin@gmail.com>
Owner
Author
|
@devin let's add an integration test that tests 2 things:
|
Co-Authored-By: Şahin Olut <olut.sahin@gmail.com>
Contributor
|
Added in 2ff739a. I extracted the serve/drain orchestration into a
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The API server previously died instantly on SIGTERM, cutting in-flight clones/upload-pack streams on every rollout or pod eviction. This adds a three-phase graceful shutdown plus matching chart settings.
App (
git-cache-api): the shutdown orchestration lives ingit_cache_api::serve()(which main now uses after the repo-access-flush refactor on main; the flush still runs after the drain):ReadinessGateflips and/healthzstarts returning503 {ok:false}, so Kubernetes/LBs pull the pod out of rotation while it still accepts traffic forshutdown.readiness_delay_seconds(default 5s — covers the endpoint-propagation race, replacing the usualpreStop sleephack).with_graceful_shutdownand drains in-flight requests.shutdown.drain_timeout_seconds(default 60s) the process exits anyway (tokio::select!against the serve future); lingering git children are reaped by the existingkill_on_drop(true)contract.New config (env or TOML, both defaulted so existing deployments are unaffected):
New API:
app_with_shutdown_async(config) -> (Router, ReadinessGate)for embedders;app_result_asyncis unchanged.Chart:
terminationGracePeriodSeconds: 75on the StatefulSet (> readiness delay + drain timeout, vs the K8s default 30s which would have SIGKILLed mid-drain) and the two shutdown env vars wired through the shared env helper.S3 kill-safety audit (mid-flight death cannot corrupt S3)
Audited the publish path for the "worker dies mid-publish" concern; ordering is already kill-safe:
GenerationPublish::publish_pack_filesuploads packs first — content-addressed keys (packs/pack-{sha256}.pack), skipped if already present.write_json_if_absent_or_matches(conditional PUT; a differing existing object errors instead of being overwritten).finish_generation_publishflip the head pointer, via a versioned compare-and-swap (write_repo_head_if_version_matches, bounded retries) that refuses to clobber a newer head.So a kill at any point leaves at worst orphaned packs/manifests (cleaned up by compaction, which is itself idempotent and conditional-PUT-safe) — readers can never observe a head referencing missing or partial data. The compaction CronJob therefore needs no special shutdown handling.
Testing
cargo fmt/cargo clippy --workspace -- -D warningsclean; unit tests pass incl. newhealthz_fails_after_shutdown_begins.helm lint+helm templateverifiedterminationGracePeriodSecondsand the new env vars render.Link to Devin session: https://app.devin.ai/sessions/2b5742d5f71145ffb644f9bf14f8ad72
Requested by: @0lut