fix: drain accepted request work before service shutdown - #1417
Open
pjb157 wants to merge 1 commit into
Open
Conversation
Deploying control-layer with
|
| Latest commit: |
eed501b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://530b0a9f.control-layer.pages.dev |
| Branch Preview URL: | https://peter-graceful-http-drain.control-layer.pages.dev |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes graceful shutdown ordering so persistence-related background services (analytics, response writers, Outlet handlers) remain available while Axum drains in-flight requests, and it ensures background=true “accepted” work is joined before persistence shuts down. It also pins outlet / outlet-postgres to specific git revisions to pick up the lifecycle/shutdown behavior needed for the fix.
Changes:
- Introduce an Outlet shutdown handle and a
cancel_after_drainhelper to flush/join accepted work and then cancel background services only after HTTP draining completes. - Track detached “accepted” work via a
tokio_util::task::TaskTracker, and routebackground=truetasks through that tracker. - Pin
outlet/outlet-postgresdependencies to specific git revs and update the workspace lockfile accordingly.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| dwctl/src/lib.rs | Refactors router construction to return an optional Outlet shutdown handle; adds accepted-task tracking and enforces post-drain shutdown ordering. |
| dwctl/src/inference/middleware.rs | Routes detached background request work through a shared TaskTracker so it can be drained on shutdown. |
| dwctl/Cargo.toml | Enables tokio-util runtime feature and pins outlet / outlet-postgres to git revisions. |
| Cargo.lock | Records the git-sourced outlet / outlet-postgres dependencies (and transitive updates) for reproducible builds. |
Comment on lines
+3458
to
+3462
| result = cancel_after_drain( | ||
| axum::serve(listener, service.into_make_service()).with_graceful_shutdown(shutdown), | ||
| accepted_tasks, | ||
| outlet_shutdown, | ||
| shutdown_token, |
Comment on lines
+3530
to
+3534
| if let Some(outlet_shutdown) = outlet_shutdown | ||
| && let Err(error) = outlet_shutdown.shutdown().await | ||
| { | ||
| tracing::error!(%error, "Outlet request logger worker panicked during shutdown"); | ||
| } |
Comment on lines
+92
to
+93
| outlet = { git = "https://github.com/doublewordai/outlet", rev = "6206a0bedc0c9a5d1ad77b837ec334642d06eea8" } | ||
| outlet-postgres = { git = "https://github.com/doublewordai/outlet-postgres", rev = "e7c8d8ee7c633183eb52ea533ef0bbdb19120a59" } |
pjb157
force-pushed
the
peter/graceful-http-drain
branch
3 times, most recently
from
July 31, 2026 20:10
bb15a6b to
e0c8b5f
Compare
pjb157
force-pushed
the
peter/graceful-http-drain
branch
from
July 31, 2026 20:13
e0c8b5f to
eed501b
Compare
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
background=truerequests before persistence shutdownIncident mechanism
On SIGTERM, the control layer cancelled shared background services before accepted request and post-response persistence work had completed. That closed analytics/response-writer channels while requests were still draining, producing the observed
channel closedfailures.Dependencies
Merge in order:
The git revisions make this branch reproducible before crate releases; they can be replaced with released versions in normal dependency maintenance.
Verification
CARGO_PROFILE_DEV_DEBUG=0 CARGO_INCREMENTAL=0 just lint rustDATABASE_URL=postgresql://localhost/dwctl_graceful_drain_20260731 RUST_TEST_THREADS=4 CARGO_PROFILE_TEST_DEBUG=0 CARGO_INCREMENTAL=0 just test rust