Repository navigation
fix: join detached cache work before embedded storage closes - #256
Conversation
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
[Medium impact] The PR appears safe to merge; no new actionable issues remain. SummaryTAG now joins detached cache work before closing embedded storage.
Both previous unnumbered findings are addressed. No new actionable issues were found. This review inspected code and tests; it did not run them. Reviews (5) · Last reviewed commit: "Merge origin/main into perfloop-pr-open-..." · Reviewed by Greptile |
Signed-off-by: Perfloop Agent <[email protected]>
|
On SIGINT or SIGTERM, a cache-enabled TAG process now seals detached-work admission, cancels the Service lifetime, and joins admitted cache users after HTTP handlers drain but before
The same process, admission, and reservation assertion is violated on test-only comparison The repository checks No production shutdown incidence or overall shutdown duration was measured. HTTP draining keeps its existing 30-second deadline; the worker join has no deadline and an uncooperative cache operation can outlast the bundled StatefulSet's 30-second grace. No fixed total completion time is promised. This ordering applies after successful HTTP draining, not to handlers that survive the deadline. See graceful shutdown. Generated by Perfloop. |
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
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
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
deploy.md described graceful shutdown twice, and the second copy said handlers surviving the drain deadline were not covered. Server.Stop now joins in-flight handlers past the deadline with a warning, and Service.Stop joins detached cache work with its own warning, so fold both sections into one that states that ordering once. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
Keep the merged graceful-shutdown section, which already covers #258's text. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
|
🎉 This PR is included in version 1.22.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
proxy.Service.Stopnow seals detached-work admission, cancels the Service lifetime, and joins admitted cache users after HTTP handlers drain but beforemaincloses embedded storage. The Service lifetime is independent of an individual request, so a cache warm can continue after a client disconnect; shutdown cancels and joins it. Full-object writes have their own registered owner, so a fetch-supervisor timeout cannot hide a still-runningPutStreamor release its reservation early. An admitted tiered cleanup retains its timeout through the conditional S3 delete and marker repair. Shutdown still joins it because cancellation after dispatch can leave the remote result ambiguous.TestShutdownWaitsForBackgroundWriterBeforeEmbeddedCloseruns TAG as a child process with embedded storage and a controlled local S3 origin. It holds an admitted writer through SIGTERM and records admission, cancellation, writer exit, and backend close. A retained result-mapping driver also runs the cold-range process after the fetch supervisor times out and the active-fetch count returns to zero, plus a separate active-writer control.TestShutdownDrainsNormalRequestWithinGracechecks an ordinary request completing within the existing HTTP grace.TestStopWaitsForWriterAfterFetchSupervisorTimesOutobserves the reservation until the writer exits, andTestTieredCleanupFinishesMarkerRepairDuringServiceStopcovers the joined conditional-delete path. The existingTestColdOwner_RangeWarmsCacheOnClientCancelintegration test remains in the suite.The same process-and-reservation assertion is violated on test-only comparison
84ae52583b59e4299e6bf23bb354c59be853f5c3and satisfied on the final source.make build,make test,make test-integration,go test -race -count=1 ./proxy, andmake lint-cipassed. The process and result-mapping drivers are retained verification support, not part of this PR.No production shutdown incidence or overall shutdown duration was measured. The HTTP drain keeps its 30-second deadline; the worker join has none, and an uncooperative cache operation can outlast the bundled StatefulSet's 30-second termination grace. No fixed total completion time is promised. This ordering applies after successful HTTP draining, not to handlers that survive its deadline. See graceful shutdown.
Generated by Perfloop.
Note
Medium Risk
Changes core shutdown and background-cache ownership across many hot paths; mis-ordering could still corrupt embedded storage or extend shutdown, though coverage is extensive.
Overview
Fixes shutdown ordering so embedded RocksDB storage is not closed while detached cache writers still run.
proxy.Service.Stop(called frommainafter the HTTP server drain) seals admission to new background work, cancels a service-wide lifetime context, and blocks until every admitted task exits—only then doesembeddedCache.Closerun. A join past 30 seconds logs a warning with the outstanding task count; there is no hard deadline on the join itself.Detached work that used bare
go func()withcontext.Background()now goes throughstartBackgroundTask/beginBackgroundTask, so block fetches, parquet footer warms, background populates, tiered cleanup, write-through tees, and similar paths are tracked and canceled on shutdown. Cache-write supervisors keep populate slots and byte reservations until the realPutStream/PutBlockowner finishes; abandoned pipe readers are closed so relays cannot blockStop.Docs (
README,docs/deploy.md) describe the two-phase shutdown (HTTP drain, then worker join) and the Kubernetes termination-grace caveat.Tests add subprocess probes for writer-before-close ordering and in-flight HTTP drain, plus unit tests for lifecycle, tiered cleanup during stop, and parquet admission after
Stop.Reviewed by Cursor Bugbot for commit 94d9f33. Bugbot is set up for automated code reviews on this repo. Configure here.