Repository navigation
fix: wait for HTTP handlers before closing cache - #258
Merged
Merged
Conversation
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
[Medium impact] The PR appears safe to merge; no actionable new issues were found. SummaryTAG now waits for admitted HTTP handlers and their synchronous cleanup before allowing the embedded cache to close.
Reviews (3) · Last reviewed commit: "Merge branch 'main' into perfloop-pr-ope..." · Reviewed by Greptile |
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
Warn once when Stop waits past the drain deadline for in-flight handlers. Resolve handlers/server.go against #259 by keeping this branch's NewServer (which already moved the http.Server literal and adds BaseContext) plus #259's comment. Adapt #259's stop-before-start test to check that the server handler dispatches to the router instead of comparing identity, since the router is now wrapped by the handler lifecycle barrier. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
ovaistariq
added a commit
that referenced
this pull request
Oct 21, 2026
Rebase #256 over #237/#239/#240 and #258: keep main's populateBlockMode split, RangeBlockSpan publication, lazyCommitWriter range serve and the 32-slot parquet footer prefetch semaphore, with every detached spawn still admitted through serviceWorkers. A footer prefetch that serviceWorkers refuses during Stop now releases its admission slot and dedup marker exactly as a finished scan would, so a shutdown-time refusal cannot leak one of the 32 permits. Service.Stop logs one Warn when its unbounded join passes 30s (main's drain timeout) with the outstanding task count, and one Info with the elapsed wait when the join then completes, mirroring warnHandlerJoinPastDeadline. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
ovaistariq
approved these changes
Oct 21, 2026
|
🎉 This PR is included in version 1.22.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
TAG closes HTTP handler admission before graceful shutdown and waits for every admitted handler through synchronous cache cleanup. If the 30-second drain expires, it cancels request contexts and closes connections, but
Stopwaits for handlers before returning so main's deferred embedded-cache close follows. Requests finishing within grace keep their normal response and post-success invalidation. Shutdown-racing S3 routes receive XMLServiceUnavailable; operational and unmatched routes retain plain HTTP 503. No S3 API or configuration changes.An atomic stop/count state closes admission and tracks in-flight handlers. Connection tracking and admission wrappers are composed once for each registered route at setup, preserving their order without rebuilding the Mux middleware chain on every match.
This condition holds with this change and does not hold at
628616fd9e19fac473837eb45eb46115e3d33313:After SIGTERM, TAG does not close its embedded cache until every admitted foreground HTTP handler and its synchronous consistency cleanup has exited, including when the drain expires..The six expiry/startup tests fail their lifecycle assertions on the starting revision and pass on the intermediate implementation and final source:
TestStopWaitsForActiveDeleteCleanupAfterDrainExpiryholds a successful DELETE's second cache delete across drain expiry and checks that the close marker does not precede cleanup and handler exit.TestStopCancelsForwardingAfterDrainExpiryverifies expiry cancels a held origin-bound DELETE and joins its handler; it waits up to five seconds for the origin to observe cancellation.TestStopJoinsDisconnectedHTTP2DeleteCleanupreturns HTTP/2 204, disconnects the stream while invalidation is blocked, and verifiesStopstill joins cleanup.TestStopCancelsIncompletePutBodyAfterDrainExpiryholds a partial PUT body and verifies request cancellation and handler exit before close.TestStartUsesHandlerLifetimeBarrierexercises the actualStartpath with a blocked handler and verifiesStopwaits.TestStopBeforeStartPreventsHTTPAndHTTPSListenverifies Stop-before-Start prevents both HTTP and HTTPS listeners.TestStopDrainsActiveDeleteWithinGracepasses on all three revisions and verifies the 204 response and both cache invalidations.TestStopRejectsRequestsAfterClosingAdmissionfails on the starting revision with 204 and dependency calls. The intermediate implementation returns HTTP 503 without calls but usestext/plain; final asserts XMLServiceUnavailable, keeps the no-call check, and confirms/healthremains plain 503.TestServerSetupAppliesAdmissionMiddlewarepasses on base, intermediate, and final source; it checks that a full S3 limit still serves/healthand sheds an object GET with XMLSlowDown.The handler unit and race suites, static build, embedded-cache integration tests, vet, formatting, and parallel
BenchmarkServerHTTPHandlersmoke run passed. The existingBenchmarkHandlerWarmedEmbeddedCacheHitusesServer.Router()and bypasses the Start/Stop lifetime gate. The new native benchmark exercises the actualhttp.Serverhandler on/health; it does not measure S3/cache throughput.make bench-warpwas not run because it requires Tigris credentials and a live upstream.make testandmake lint-ciremain for target CI.The cache-ordering unit tests use a recording memory-cache client. A separate Go subprocess harness, not included in this PR, sends SIGTERM to a child test process that calls TAG's
Server.Stopwith a real single-node embedded cache and a held origin response. It does not launch thetagbinary. The harness uses a 2-second test drain to expose expiry; production remains at 30 seconds. It establishes ordering for this constructed schedule, not backend-corruption rates or production incidence. Kubernetes also grants 30 seconds for termination and may stop the process while uncooperative cleanup is still running; there is no fixed completion guarantee in that case.Generated by Perfloop.
Note
Medium Risk
Changes core shutdown and request admission behavior under SIGTERM; mis-tuned pod termination grace could still kill the process during long cleanup, but the fix reduces cache-use-after-close risk during rollouts.
Overview
TAG now tracks admitted HTTP handlers through shutdown so the embedded cache is not closed while synchronous handler work (including post-response cache invalidation) is still running.
Server.Stopcloses handler admission first, runs the usual HTTP drain (30s in production), and if the drain expires cancels request contexts and force-closes connections—but still blocks until every admitted handler exits before returning. Late S3 traffic gets XMLServiceUnavailable;/healthand other operational paths keep a plain HTTP 503.Routing middleware is wrapped once per route at setup (connection tracking + admission) instead of
Router.Use, avoiding mux rebuilding middleware on every match. Docs (README,docs/deploy.md) describe the drain window and how KubernetesterminationGracePeriodSecondsrelates to handler cleanup.Coverage adds extensive shutdown lifecycle tests (DELETE cleanup past drain, HTTP/2 disconnect, partial PUT cancel, admission after stop) plus a small benchmark on the real
http.Serverhandler stack.Reviewed by Cursor Bugbot for commit 7c0573c. Bugbot is set up for automated code reviews on this repo. Configure here.