p4: fix pre-existing tls feature breakage in justapi-core (ADR-066)
swadhinbiswas committed 3 months ago
0be53e5
1 parent a47339c
commit 0be53e5
2 files changed
+34 -1
Showing 2 changed files+34-1
▼DECISIONS.md
+31-0
| @@ -2477,3 +2477,34 @@ to 3 (log: "scaled up load=0.08 workers=2/3"); `--workers 3 --min-workers 1 | ||
2477 | 2477 | (graceful, not restarted). SIGTERM in both cases drains the tree to exit 0. |
2478 | 2478 | Clippy `-D warnings` + `fmt` clean. No new dependency (reuses `libc`, |
2479 | 2479 | `available_parallelism`). |
2480 | + | |
2481 | +## ADR-066 — 2026-07-18 — Fix pre-existing `tls` feature breakage in `justapi-core` | |
2482 | + | |
2483 | +**Context:** `cargo build -p justapi-core --features tls` failed to compile | |
2484 | +before any of ADR-060..065 touched it — a pre-existing defect in | |
2485 | +`serve_with_tls` (the TCP+TLS accept loop in `crates/justapi-core/src/server/mod.rs`), | |
2486 | +not caused by the worker/UDS/XML work. The function param `static_mounts: | |
2487 | +Vec<StaticMount>` was captured by the per-request `service_fn(move |req| ...)` | |
2488 | +closure (an `Fn`, invoked for every request) and referenced by move, producing | |
2489 | +`E0507` ("cannot move out of `static_mounts`, a captured variable in an `Fn` | |
2490 | +closure") and `E0382` ("use of moved value: `static_mounts` in previous | |
2491 | +iteration of the loop"). A second latent clippy lint (`if let Some(_) = | |
2492 | +shutdown`) in the same function also broke `-D warnings`. | |
2493 | + | |
2494 | +**Decision / change:** | |
2495 | +- Mirror the already-correct pattern in non-TLS `serve_connection`: | |
2496 | + - Clone `static_mounts` once per loop iteration from the function param (alongside | |
2497 | + `chain`/`static_dir`/`metrics`) so the value is re-acquired each iteration and | |
2498 | + never moved out of the per-iteration scope. | |
2499 | + - Inside the `service_fn` closure, `let static_mounts = static_mounts.clone();` | |
2500 | + so the `Fn` closure borrows its own copy to `.clone()` per request instead of | |
2501 | + moving a `Vec` out of a captured variable. | |
2502 | +- Replace `if let Some(_) = shutdown` with `if shutdown.is_some()` to satisfy | |
2503 | + `clippy::redundant_pattern_matching` under `-D warnings`. | |
2504 | + | |
2505 | +**Evidence:** `cargo build -p justapi-core --features tls` now compiles. | |
2506 | +`cargo test -p justapi-core --features "tls,db"` green (274 core + 8 xml + 15 | |
2507 | +wasm + 1 tracer). `cargo clippy --workspace --tests --features | |
2508 | +"justapi-core/db,justapi-core/tls" -- -D warnings` clean; `cargo fmt --check` | |
2509 | +clean. No new dependency, no public API change (internal function only). | |
2510 | + | |
2480 | 2511 | |
▼crates/justapi-core/src/server/mod.rs
+3-1
| @@ -1965,6 +1965,7 @@ async fn serve_with_tls( | ||
1965 | 1965 | let acceptor = acceptor.clone(); |
1966 | 1966 | let chain = chain.clone(); |
1967 | 1967 | let static_dir = static_dir.clone(); |
1968 | + let static_mounts = static_mounts.clone(); | |
1968 | 1969 | let conn_metrics = metrics.clone(); |
1969 | 1970 | let wasm_middleware = wasm_middleware.clone(); |
1970 | 1971 | |
| @@ -1990,6 +1991,7 @@ async fn serve_with_tls( | ||
1990 | 1991 | let chain = chain.clone(); |
1991 | 1992 | let arena = arena.clone(); |
1992 | 1993 | let static_dir = static_dir.clone(); |
1994 | + let static_mounts = static_mounts.clone(); | |
1993 | 1995 | let metrics = spawn_metrics.clone(); |
1994 | 1996 | let wasm_middleware = wasm_middleware.clone(); |
1995 | 1997 | #[cfg(feature = "ws")] |
| @@ -2194,7 +2196,7 @@ async fn serve_with_tls( | ||
2194 | 2196 | }); |
2195 | 2197 | } |
2196 | 2198 | |
2197 | - if let Some(_) = shutdown { | |
2199 | + if shutdown.is_some() { | |
2198 | 2200 | tracing::info!("Waiting for {} active TLS connections to drain...", connections.len()); |
2199 | 2201 | tokio::select! { |
2200 | 2202 | _ = async { while connections.join_next().await.is_some() {} } => { |
2201 | 2203 | |