From 9d6fbd32887de81bbc294623f086856fe0e1743c Mon Sep 17 00:00:00 2001 From: ari Date: Mon, 19 Oct 2026 20:25:14 -0400 Subject: [PATCH] B: B4 empty the peer snapshot when a reload disables the feature --- plan/phase-5-consolidator/ws-b-registry.md | 2 +- src/peers/registry.rs | 43 +++++++++++++++------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/plan/phase-5-consolidator/ws-b-registry.md b/plan/phase-5-consolidator/ws-b-registry.md index a9f1bc7..b6ec69a 100644 --- a/plan/phase-5-consolidator/ws-b-registry.md +++ b/plan/phase-5-consolidator/ws-b-registry.md @@ -54,7 +54,7 @@ Integration test starts a second in-process server (fake sources) as a peer and - 2026-10-19 B2: one task per peer (both probes in one `tokio::select!`) with a deterministic name-hash jitter capped at a quarter of the shorter interval. Probes are `health::probe_server` / `health::probe_api`; `check_once` joins them for A4. A 401/403 is `api.up = true, auth = rejected`; a 404 falls back to public `/healthz` with `auth = unknown` (older peers, D4). The loop reuses `FakeTransport` for the classification/threshold tests and a second in-process `slinuxm` (fake sources) for up/down/recovery, api-down-but-server-up (listener accepts, never answers) and rejected-token cases in `tests/peers_registry.rs`. - 2026-10-19 B3: `ServerTracker`/`ApiTracker` keep `since` and consecutive failures in loop-local state, so a surviving peer keeps its timestamps across a reload and a restart resets them. `fail_threshold` consecutive failures flip a check down; a success recovers in one check. `last_error` is always the fixed class string (never peer text or a URL). The first check records `since` whether it is up or down. -- 2026-10-19 B4: `PeerRegistry::start` builds the real transport and loops; `src/main.rs::serve()` assigns `state.peers`. SIGHUP now reloads TLS (when enabled) and peers from one handler (`tls::spawn_sighup_reload`); a config error is logged and the old registry stays. `reload` keeps statuses of surviving peers, cancels removed/disabled/changed loops and starts new ones. Token files are read on every API check, so agenix rotation needs no restart. `peers` concurrency and size caps are fixed for the process lifetime; only the peer set, intervals, timeouts and threshold follow a reload. `PeerRegistry::shutdown` cancels and joins loops with a 5 s bound. +- 2026-10-19 B4: `PeerRegistry::start` builds the real transport and loops; `src/main.rs::serve()` assigns `state.peers`. SIGHUP now reloads TLS (when enabled) and peers from one handler (`tls::spawn_sighup_reload`); a config error is logged and the old registry stays. `reload` keeps statuses of surviving peers, cancels removed/disabled/changed loops and starts new ones. Token files are read on every API check, so agenix rotation needs no restart. `peers` concurrency and size caps are fixed for the process lifetime; only the peer set, intervals, timeouts and threshold follow a reload. `PeerRegistry::shutdown` cancels and joins loops with a 5 s bound. A reload with `[peers] enabled = false` empties the snapshot (routes stay mounted until restart). `main()` passes the config path and CLI overrides into `serve()` because a SIGHUP reload must re-read the same file; that is the only edit outside `serve()`. - 2026-10-19 B5: connect-time SSRF guard resolves the peer host, rejects any address in `deny_cidrs` (parsed with `ipnet` at `ReqwestTransport::new`), and pins the allowed address into the HTTP client; plain HTTP to a non-loopback host requires `allow_plain_http`. `tcp_check` uses the same resolution and guard. DNS failures map to `dns`, all-denied to `unreachable`. ## Handoff (2026-10-19) diff --git a/src/peers/registry.rs b/src/peers/registry.rs index 77849e7..fddf901 100644 --- a/src/peers/registry.rs +++ b/src/peers/registry.rs @@ -266,19 +266,25 @@ impl PeerRegistry { { let mut st = lock_write(&self.shared.state); let old = std::mem::take(&mut st.statuses); - st.statuses = new - .peer - .iter() - .map(|peer| { - let mut status = old - .get(&peer.name) - .cloned() - .unwrap_or_else(|| initial_status(peer)); - status.enabled = peer.enabled; - status.url = peer.display_url(); - (peer.name.clone(), status) - }) - .collect(); + // Turning the feature off renders an empty list rather than a + // stale snapshot; the routes themselves stay mounted until + // restart because the router is built once. + st.statuses = if new.enabled { + new.peer + .iter() + .map(|peer| { + let mut status = old + .get(&peer.name) + .cloned() + .unwrap_or_else(|| initial_status(peer)); + status.enabled = peer.enabled; + status.url = peer.display_url(); + (peer.name.clone(), status) + }) + .collect() + } else { + BTreeMap::new() + }; st.config = Arc::new(new.clone()); } if self.loops_enabled { @@ -600,6 +606,17 @@ mod tests { }); } + #[tokio::test] + async fn reload_disabling_the_feature_empties_the_snapshot() { + let reg = registry_with(FakeTransport::new(), fake_peers_config(&["beta"])); + let mut new = fake_peers_config(&["beta"]); + new.enabled = false; + reg.reload(new).await.unwrap(); + assert!(reg.snapshot().is_empty()); + assert!(reg.status("beta").is_err()); + assert!(!reg.config().enabled); + } + #[tokio::test] async fn reload_moves_loops_to_the_new_peer_set() { let fake = FakeTransport::new();