Repository navigation
Add Axum production startup and bounded shutdown - #406
ChristianPavilonis wants to merge 23 commits into
Conversation
3ab2209 to
49ba021
Compare
|
For the identity integration branch (#495), I pushed |
…rocesses This carries the production_hosting.rs changes that PR #519 makes in 09b09d9 and d86a5d3 (prk-Jr) to the helpers and tests this PR owns: the reservation/spawn lock, reserved_address() holding a bound but not listening socket for "nothing answers" checks, the lock around signals and client connects, and the failed-startup check that the host never reached its listener bind. A released reservation could otherwise be served by another test's host during a failed-startup check ("failed startup never accepts connections"). The hunks are byte for byte except reserved_address(), which binds SocketAddr::from(([127, 0, 0, 1], 0)) because Ipv4Addr is not imported here yet; PR #519's merge restores its Ipv4Addr::LOCALHOST line.
…istener address() releases its reservation before the host binds, so another test's listener can take the port first. ready() then accepted that listener's 200, and later requests reached the wrong server; a decoy listener on the released port reproduces the failure every time. The fixture gains a /fixture-ready route that returns probe::readiness's response plus the launching test's per-spawn token in x-fixture-spawn; /ready itself is unchanged. Server keeps its command, and ready() polls /fixture-ready and respawns the host on a fresh reservation when it answers without the token or the host exits reporting a lost bind, at most 3 attempts, then fails naming the cause. Server::addr() returns the address the live host serves. Binding port 0 in the host and reporting the address would remove the race at its source; that is a larger change across every test.
|
For the identity integration branch (#495), I pushed
|
|
Review follow-up for 48097ab. Inline replies cover the CI gate, port handling, startup logging and diagnostics, shutdown policy, stores, and router replacement. A few points from the review summaries:
Local verification passed: 20 hosting subprocess tests through the CI wrapper, Axum all-features tests, workspace all-target tests, strict workspace Clippy, WASM compile checks, workflow lint, and docs lint/format/build. One unchanged isolated-harness port-close test failed in the parallel suite and passed on its own. macOS and release/container acceptance were not rerun. |
Carry the selected Axum JSON ceiling through shared service preparation while preserving the hosting lifecycle and both sets of subprocess cases.
prk-Jr
left a comment
There was a problem hiding this comment.
PR Review
Summary
Follow-up review at 48097ab1. 48097ab1 resolves every code-level blocking finding from the three earlier reviews. The hosting suite runs in CI, embedding leaves the host logger alone, the dev URL and bind categories are back, dev shutdown is SIGINT-only cancel again, and the guide matches. One earlier blocking item is still open, and it is only in the PR description: it still says Closes #392 / Closes #396. That's the only reason this is still changes requested.
😃 Praise
RunModenow sets the shutdown policy explicitly. Development cancels, embedded production drains with no signal handlers, and standalone production drains with SIGINT/SIGTERM. The listener source now only decides how the listener is acquired.- The new subprocess tests act as real controls. I changed the standalone-only
init_loggingguard so embedding also installs a logger, andrepeated_embedding_keeps_the_host_logger_and_filterfailed. I reverted the change afterwards. KvOpenFailure/SnapshotOpenFailurereplace the string-matched categories with typed reasons. I checked the redb 4.4.0 source:DatabaseAlreadyOpenis what the page manager returns on lock contention, so the "locked by another owner" assertion now tests lock detection.
Prior findings status
| Prior finding | Status | Evidence at 48097ab1 |
|---|---|---|
| Subprocess suite never runs in CI | ✅ resolved | test.yml:150-162 runs it through run_test_nonzero.sh; hosted workspace tests log shows running 20 tests … 20 passed, followed by the three WASM production_handlers checks |
| Port reservation race | ✅ resolved | Spawn/reserve lock plus token-checked respawn (production_hosting.rs:63-100, ready()); 7/7 default-parallel runs passed locally on macOS |
Embedding installs a global logger; standalone installs it after App::build; build failure loses the startup …: prefix |
✅ resolved | dev_server.rs:1074-1078 installs the logger only for standalone, before App::build, and maps failure to startup configure: application: assembly failed; mutation control above |
| Dev startup lost listening URL / every bind error reads "address unavailable" | ✅ resolved | announce_ready logs native server ready on http://{bound} for dev binds; adopt_listener (dev_server.rs:546-561) maps in-use / not-available / permission-denied separately |
Dev Ctrl-C/SIGTERM behaviour change, serve() takes over SIGTERM, guide stale |
✅ resolved | Signals::register registers SIGTERM only for ProductionStandalone (dev_server.rs:354); development clears tasks without a drain; legacy_dev_leaves_sigterm_to_the_host / legacy_dev_ctrl_c_cancels_without_a_drain_budget; axum.md "Choose an entrypoint" and "Production shutdown" |
Closes #392 / Closes #396 with acceptance work remaining |
🔧 still open | PR body unchanged; closingIssuesReferences still lists #392 and #396 (see Blocking) |
🤔 App::set_router undocumented/untested (non-blocking) |
✅ resolved | Rustdoc at app.rs:591-596, guide paragraph, and startup_router_replacement_rejects_admission_for_a_different_router |
| ⛏ PR body out of date (non-blocking) | still open | See below |
Findings
Blocking
- 🔧 PR still auto-closes #392 and #396: The description still contains
Closes #392./Closes #396., and GitHub lists both underclosingIssuesReferences. The follow-up comment says both issues "should remain open" until acceptance is done (adoption/storage guides, release/Docker UID evidence, unreadable mounts, the #275 re-audit), and the design doc (line 425) says the same. When this stack lands onmain, merging closes both issues, and the remaining acceptance work loses its tracker. Fix: change both lines toPart of #392/Part of #396. No code change needed.
Non-blocking
- 🤔 Dev bind failures no longer name the address (
dev_server.rs:559, inline). - ⛏ PR description is still stale: It has three different "current head" values (
9f090e57,1b5e361e,a13f68a0), still says it "remains draft", and the Changes table doesn't listApp::set_router,PreparedStores,AxumRunOptionsor the probe module. Please rewrite the top of the description for48097ab1when you fix the closing keywords.
📌 Out of Scope
- The generator image-helper fix (
9f090e57) is still part of this PR. I'm fine with the reason given for keeping it.
CI Status
- Hosted (head
48097ab1): all 29 checks pass, includingworkspace tests, which ran the 20 production-hosting subprocess tests and the WASMproduction_handlerschecks. - Local (macOS):
- fmt: PASS
- clippy (Rust 1.98.1,
-p edgezero-adapter-axum -p edgezero-core -p edgezero-cli --all-targets --all-features -D warnings): PASS cargo test -p edgezero-adapter-axum --all-features: PASS (357 unit, 28 contract, 20 hosting)cargo test -p edgezero-core: PASS- Hosting suite (
--features axum,test-utils --test production_hosting, default parallel): 7/7 runs PASS
- Not re-run locally: full workspace suite, Spin/Fastly/Cloudflare WASM builds,
examples/app-demo.
| } else { | ||
| "bind failed" | ||
| }; | ||
| failure("bind", "listener", category) |
There was a problem hiding this comment.
🤔 Dev bind failures no longer name the address
The categories are right now, thanks. But on the dev path (run_app / AxumDevServer::run), the error used to say which address failed (failed to bind dev server to 127.0.0.1:8787: …). It now reads only startup bind: listener: address in use. The resolved address isn't logged before the bind either, so if EDGEZERO__ADAPTER__PORT was overridden somewhere, the developer can't see which port they collided on. In production, keeping the address out of the error is deliberate (occupied_bind_is_a_real_redacted_process_failure asserts it), but a dev bind address isn't sensitive. Not blocking. One option is to log binding http://{addr} at info level before adopt_listener when report_url is true.
| enum RunMode { | ||
| Development { ctrl_c: bool }, | ||
| ProductionEmbedded(Duration), | ||
| ProductionStandalone(Duration), |
There was a problem hiding this comment.
😃 Making the shutdown policy an explicit RunMode fixes the earlier coupling between drain and listener source cleanly. Signals::register keys SIGTERM off ProductionStandalone only. Development and serve() are back to SIGINT-only cancel, and embedding registers nothing.
| async move { | ||
| let metadata = A::stores(); | ||
| options.validate_stores(metadata)?; | ||
| if matches!(mode, RunMode::ProductionStandalone(_)) { |
There was a problem hiding this comment.
😃 Installing the logger only in standalone mode, before App::build, resolves both logger issues. I checked that this guard is tested: with it changed to unconditional, repeated_embedding_keeps_the_host_logger_and_filter fails. I reverted the change afterwards.
| )] | ||
| fn from_database(error: &DatabaseError) -> Self { | ||
| match error { | ||
| DatabaseError::DatabaseAlreadyOpen => Self::Locked, |
There was a problem hiding this comment.
😃 In redb 4.4.0, the page manager returns DatabaseAlreadyOpen when it can't take the file lock, so this mapping makes the "locked by another owner" assertion in the competing-writer test actually check lock detection. It no longer matches a catch-all message.
dhruv8sh
left a comment
There was a problem hiding this comment.
PR Review
Summary
This PR adds strict production entrypoints for Axum: run_production_app plus an initializer variant, and run_app_with_options plus an initializer variant for embedding. All of them run on one shared run_local/run_owned lifecycle owner. They add validated AxumRunOptions, required config/KV startup, lifecycle observation, a gate that blocks dispatch once draining starts, a bounded graceful drain, and portable probe helpers in core. The design is careful and well tested. I found no blocking issues, only a few non-blocking suggestions.
😃 Praise
- Development and production now share one runtime owner, and dev behaviour is unchanged (Ctrl-C cancels immediately, no SIGTERM, no grace setting). The subprocess tests in
production_hosting.rsshow both behaviours. - Startup errors go through
failure(stage, subject, category), which drops source chains, so neither provider errors nor setting values can leak into logs. The sentinel-based tests confirm it. build_kv_registryandbuild_production_storesnow reuse one handle when several ids resolve to the same store name. Before, aliased ids would hit redb'sDatabaseAlreadyOpen.- Moving
AppConfigextraction tofrom_binding, with secrets, limits and clock passed in, lets startup and request extraction share the same validation path.
Findings
Blocking
None.
Non-blocking
- 🤔 Draining gate drops already-parsed requests with no response: a request that is already in flight when the phase changes is aborted (
AxumIngressAbort), not answered with a 503 andConnection: close(crates/edgezero-adapter-axum/src/service.rs:195). - 🤔 Test fixture is shipped as a
[[bin]]of the library crate, andtest-utilsnow pulls invalidatorfor downstream users (crates/edgezero-adapter-axum/Cargo.toml:70). - ⛏ Initializer failure category comes from
Debugoutput (crates/edgezero-adapter-axum/src/dev_server.rs:1083).
📌 Out of Scope
probe::liveness/readinessdocument 200/503 responses for Starting and Draining. The native gate never dispatches in those phases, so the Axum adapter can't actually serve those rows. The docs already say "applies only if the handler executes". It may be worth tracking whether a later adapter should answer probes during drain.
| ) -> Result<Response<AxumEgressBody>, AxumIngressAbort> { | ||
| // This private gate defines dispatched work. Public extensions and app | ||
| // admission policy cannot admit new work after the owner starts draining. | ||
| if !self.admission_open() { |
There was a problem hiding this comment.
🤔 Draining aborts already-parsed requests with no response: graceful_shutdown() stops hyper from reading new requests, but a request that was already read when the phase changes (for example a pipelined request, or one racing the signal) reaches this gate and gets AxumIngressAbort. The connection is then torn down with no response. The client sees a reset/EOF, so it can't tell whether the request was processed or is safe to retry.
If the runner is draining, a framework 503 with Connection: close (and possibly Retry-After) would tell clients the request was never dispatched. That would also keep ordinary HTTP clients from seeing it as a transport failure. Not blocking; the current behaviour still never dispatches work after drain starts.
| [target.'cfg(unix)'.dependencies] | ||
| libc = { workspace = true } | ||
|
|
||
| [[bin]] |
There was a problem hiding this comment.
🤔 Test fixture registered as a crate binary: edgezero-hosting-fixture is now a real [[bin]] target of the adapter library. Because of it, test-utils also enables dep:validator (line 34), which the fixture needs only through production_handlers.rs. Downstream crates that enable edgezero-adapter-axum/test-utils for their own tests will now compile validator, and cargo build --all-features will build the fixture binary.
One option is a small unpublished workspace crate (for example crates/edgezero-adapter-axum-hosting-fixture) that owns the binary and the validator dependency. The integration test can then find it with CARGO_BIN_EXE_* from a dev-dependency, or by building it explicitly. That keeps the adapter's feature surface unchanged.
| let transport = AxumOutboundClient::try_transport() | ||
| .map_err(|_error| failure("transport", "HTTP client", "initialization failed"))?; | ||
| initialize(&mut app, &stores).await.map_err(|error| { | ||
| let category = error.store_extraction_reason().map_or_else( |
There was a problem hiding this comment.
⛏ Error category derived from Debug: format!("{reason:?}") ties the operator-visible startup category to the derived Debug output of StoreExtractionReason. Renaming a variant or changing the derive would silently change log/error text that supervisors may match on. A stable as_str()/category() on the reason, like KvOpenFailure::category and SnapshotOpenFailure::category in this PR, would keep these categories consistent and avoid allocating here.
Current review readiness — 2026-11-10
Ready for review at the publication head below. All29 current hosted checks passed. Reviewers:
aram356,prk-Jr,dhruv8sh.Review transitions are independent of TS work and the combined integration audit; #462 remains draft. This current status supersedes historical draft-only prerequisites below without claiming unexecuted deployment/manual acceptance complete. All three reviewers are requested. Stack465 is the current grouping; #453 is excluded.
Current review-stack checkpoint
Publication head:
9f090e573206cf0d8c21c1ce0067afffd69f12db. This cleanup preserves the existing feature unit and PR identity. The additional change is the completed generated-native build correction: image-only code now follows the scaffold's existing Fastly-example selection, with no request-policy change. Its focused generator/native proof is retained; fresh per-branch hosted checks are not assumed green.Review order: #275 → #406 → #407 → #409 → #414 → #422 → #439 → #454. Draft integration checkpoint: #462. New SDK/group/codec/phase development and unrelated TS work are not prerequisites or additions to this PR. Earlier notes below retain their original tested revisions and limits; they are not a whole-tree pass for this new head.
Earlier implementation and proof notes
RC refresh checkpoint, 2026-11-10
Current head:
1d8e42e1cba52610e6655965e9941f42680b53ab.Current #275 hosting port, with bounded startup/config/ingress and existing callback/egress ownership retained. The invalid-present native-limit and Windows prefix-identity capture bugs found by review are fixed. Windows semantics were simulated at the private parser boundary, not run on Windows.
Fresh CI exposed missing fixture validator metadata, an always-compiled test listener helper and a trigger assertion still expecting main-only PRs. The fixture lock is synced, the helper now has the same test/test-utils gate as its caller, and the exact workflow test now requires all PR bases while retaining main-only push. No lint suppression or production/deployment trigger expansion. Parent proof includes 301 Axum unit tests, axum-only strict Clippy and 35 Node CI tests.
Draft pending fresh hosted checks and the combined RC audit. Two unchanged native default-parallel deadline misses remain recorded and unclassified; serial passes and untouched-foundation parallel passes do not clear them. No timing bound was relaxed. No deployment, main merge, security-alert dismissal or review-thread resolution occurred. Historical design/review context follows.
Summary
This PR is stacked on #275, with base branch
docs/outbound-http-spec. The implementation started at5527b58. It remains draft because #275 has advanced to91f4af38, five parent-only commits beyond the common base5527b58. Parent integration and re-audit, including the previously identifieddev_server.rsconflict, remain outstanding. The recorded checks are for this branch, not integration with the current prerequisite. This relationship audit performed no merge or rebase. Integrate the current contracts and repeat affected validation before marking ready.Changes
edgezero-adapter-axum/src/dev_server.rs,run_options.rsedgezero-core/src/app.rs,router.rsedgezero-core/src/extractor.rs,probe.rsCloses
Closes #392.
Closes #396.
Part of #391. This PR remains draft until the pending integration and acceptance work below is complete.
Remaining acceptance includes production adoption/storage guides, standalone release and Docker UID evidence, unreadable/unusable mount cases, retained-handle lock evidence, and the accepted-#275 re-audit.
Test plan
cargo test --workspace --all-targetscargo clippy --workspace --all-targets --all-features -- -D warningscargo fmt --all -- --checkcargo check --workspace --all-targets --features "fastly cloudflare spin"examples/app-demoworkspace:cd examples/app-demo && cargo test --workspace --all-targetscd docs && npm run lint && npm run format && npm run buildedgezero serve --adapter axumcargo test -p edgezero-core --all-targetscargo test -p edgezero-adapter-axum --all-targets --all-features, including all 13 production-hosting subprocess testscargo check -p edgezero-adapter-spin --target wasm32-wasip2 --features spincargo check -p edgezero-core --test production_handlers --target <target>forwasm32-wasip1,wasm32-wasip2, andwasm32-unknown-unknowngit diff --checkChecks passed on this branch, not on a merge with the newer prerequisite. Native subprocess tests use debug fixtures and the current user's UID, not a release container image. Shutdown cancellation is cooperative; blocking application code still requires a supervisor hard-kill boundary.
Checklist
{id}syntax, not:idedgezero_core, nothttpKvRegistry/ConfigRegistry/SecretRegistryTS cutover follow-up, November 11
Adds startup-only router installation without rebuilding application clocks, platform metadata, or admission/egress policies. This lets a prepared-store initializer assemble application routes before the listener is shared.
Current head:
1b5e361e4896ad098fc26925556eb58b52ecdbb6.Local combined-RC qualification at
36f8e9c9c2c93661aaa73f2ca956cec3bc9e4c92: workspace tests 2,947 passed / 6 ignored; all-feature Axum 568 passed, including 36 production-hosting, 6 AWS startup and 4 celld startup cases; core doctests 19 passed / 13 ignored; strict workspace Clippy, formatting, feature compilation and Spin WASM check passed under Rust 1.98.1. Narrow TS consumer proof under Node 24.20.0: all four real proxy tests and typed prepared config/secrets/router startup passed. This is not final TS-stack/image/deployment qualification. Fresh hosted checks are still required.Owned follow-up review checkpoint
a13f68a05c3028dff9a911b22475eb75dc8c883c. Source tree30d6b8ae249b4dd7edd0c0308ebdde8207ebc3c1is byte-identical to previous head6d1dda164bc60459ec91ab5343195fa4f729ad00.docs/outbound-http-specbase are preserved. Only owned branch history was advanced; no update to feat: implement portable outbound HTTP and request lifecycle contracts #275 was made.