Repository navigation
feat(node): add admin_v1_drain + decdn node drain subcommand (#244) - #382
Conversation
Adds a loopback JSON-RPC entry point for graceful shutdown that mirrors the existing admin_v1_peersList / decdn node peers pair. Fire-and-forget semantics: the RPC fires a runtime DrainTrigger and returns initiated=true immediately, after which the runtime runs the same shutdown sequence SIGTERM triggers (stops accept loops, awaits in-flight ProtocolHandler::shutdown, flushes cache, drains within SHUTDOWN_DEADLINE). Operators observe completion via process exit (systemd/K8s) or by polling decdn node health until ECONNREFUSED. ADR 025 already pre-allocated this method name in its "Future methods" list, so no new ADR is needed. The ShutdownSignal enum gains an AdminDrain variant whose Display impl renders as "admin-drain" for the existing structured "shutdown signal received" log line. Drive-by: fix a pre-existing test-target compile error in runtime/reload.rs's test fixture. PR #312/#372 added decompress and pinned_hashes fields to ResolvedCache but didn't update this fixture, which blocked cargo nextest. Mirrors the defaults used at reload.rs:744. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a graceful shutdown mechanism for the node, accessible via a new admin_v1_drain RPC endpoint and a decdn node drain CLI command. It utilizes a DrainTrigger based on tokio::sync::Notify to signal the runtime loop to initiate shutdown. The review feedback focuses on improving security by preventing the potential leakage of credentials in error messages that include raw URLs.
There was a problem hiding this comment.
Pull request overview
Adds a graceful “drain” control-plane action to the deCDN node, exposed consistently via the loopback admin JSON-RPC surface and the decdn node CLI, and wires it into the runtime’s existing graceful shutdown path.
Changes:
- Add
admin_v1_drainRPC method backed by aDrainTriggerand aDrainResponse { initiated: true }response. - Add
decdn node drainCLI subcommand that callsadmin_v1_drain, with consistent timeout validation and error classification. - Wire drain-triggered shutdown into the runtime’s main select loop and extend shutdown logging with
signal=admin-drain; fix a test-fixture compile break in runtime reload tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/admin.rs | Adds DrainTrigger, DrainResponse, and admin_v1_drain RPC wiring into the admin server state/trait/impl. |
| crates/node/src/runtime/mod.rs | Installs a drain trigger in the runtime and maps it to a new ShutdownSignal::AdminDrain with stable display string. |
| crates/node/src/commands/node.rs | Implements decdn node drain command path, including timeout validation and JSON/plain output. |
| crates/node/src/commands/mod.rs | Re-exports the new drain command function from the commands module. |
| crates/node/src/cli/node.rs | Adds the Drain subcommand and its CLI args/help text. |
| crates/node/src/cli/mod.rs | Re-exports DrainArgs alongside other node subcommand args. |
| crates/node/tests/admin_peers.rs | Extends integration tests to cover admin_v1_drain and the CLI drain error/timeout paths; updates admin state construction. |
| crates/node/src/runtime/reload.rs | Fixes a test-target compile error by adding missing ResolvedCache fixture fields (decompress, pinned_hashes). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Three doc-only fixes from review: - AdminState::drain_trigger doc said "Always Some" but the field is Arc<DrainTrigger> not Option<…>. Reword to "always present" and call out the contrast with the Option-typed announce_trigger / reload_hook. - DrainResponse and DrainArgs docs called the admin server "the first surface to stop" during shutdown, but runtime::run signals metrics before admin. Both are stopped before router.shutdown, so "one of the first surfaces" is the accurate phrasing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
) - `admin_v1_drain` trait rustdoc: SHUTDOWN_DEADLINE bounds only the post-router task drain, not router.shutdown() — a stuck ProtocolHandler::shutdown hangs the runtime, the deadline doesn't cut it short. Previous wording implied the deadline gated the whole router-shutdown path. - `drain()` handler: comment distinguishes "trigger fired" from "runtime is now in the AdminDrain branch". If SIGTERM/SIGINT raced the RPC, the runtime has already passed `drain_trigger.wait()` and this `fire()` lands in an abandoned arm; functionally fine but a future reader shouldn't infer causation from `initiated=true`. - Coalesce test renamed `_double_fire_` → `_repeated_fire_` and adds a third `fire()` so it's robust against a "burns one permit per fire" reimplementation. Dropped the "oneshot" framing — a oneshot swap fails to compile (Sender::send consumes self) so that wasn't the regression class the test actually defends against. - `NodeCommand::Drain` variant rustdoc echoes the connection-closes- before-exit warning that `DrainArgs` already carries, so operators reading just the variant doc get the same heads-up. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
admin_v1_drainJSON-RPC method +decdn node drainCLI subcommand (issue Add adecdn node drainsubcommand that stops accepting new connections and waits for in-flight transfers to complete before shutdown #244, ADR 025) — mirrors the existingadmin_v1_peersList/decdn node peerspair per @alpergundogdu's scoping comment on the issue.DrainTrigger, returnsinitiated=true, runtime runs the same graceful shutdown sequence SIGTERM triggers (stop accept loops → await in-flightProtocolHandler::shutdown→ flush cache → drain withinSHUTDOWN_DEADLINE).ShutdownSignal::AdminDrainvariant renders assignal=admin-drainin the structured shutdown log line, so operator dashboards can distinguish RPC-initiated drains from OS signals.runtime/reload.rsleft behind by PR Add gzip or zstd response decompression support to HttpOrigin so that operators can configure origins that serve compressed blobs and reduce egress bandwidth from the origin backend #312/feat(cache): gzip/zstd decompression + blob pinning list (#312, #276) #372 (missingdecompress/pinned_hashesonResolvedCachetest fixture). Mirrors the defaults already used atreload.rs:744.Test plan
Closes #244.
🤖 Generated with Claude Code