From b8ef6c62aed313575fcb1e2642b6304addaa53a7 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 11 Sep 2026 00:42:28 +0200 Subject: [PATCH] Odin exits cleanly on SIGTERM; bootstrap waits up to five minutes for its lease Idunn runs the daemon as PID 1 of its own PID namespace, and a namespace init ignores every signal it has not caught. Every stop was a ninety-second wait for SIGKILL, which is what fencing the incumbent cost tonight's fold-back candidate: it gave up on its sixty-second bootstrap wait before Idunn could grant the lease. Odin now catches SIGTERM and SIGINT and returns from its loops; the bootstrap wait is bounded at five minutes, with Idunn's abort as the real owner of a candidate nobody leases. Verified in rust:1.95-bookworm on yggdrasil: 22 + 13 (+1 ignored) + 4 passed. Co-Authored-By: Claude Fable 5.1 --- Cargo.lock | 21 +++++++++++++++++++++ crates/odin-daemon/Cargo.toml | 1 + crates/odin-daemon/src/main.rs | 25 ++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 5aeea89..baeed16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -609,6 +609,7 @@ dependencies = [ "fs2", "rmp-serde", "serde", + "signal-hook", "tempfile", ] @@ -892,6 +893,26 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" +[[package]] +name = "signal-hook" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + [[package]] name = "signature" version = "2.2.0" diff --git a/crates/odin-daemon/Cargo.toml b/crates/odin-daemon/Cargo.toml index f170a02..1952118 100644 --- a/crates/odin-daemon/Cargo.toml +++ b/crates/odin-daemon/Cargo.toml @@ -10,6 +10,7 @@ name = "odin_daemon" path = "src/lib.rs" [dependencies] +signal-hook = "0.3" anyhow = "1" chrono = "0.4" cultcache-rs = { git = "https://github.com/GameCult/CultLib.git", rev = "a8aeddacab7dd4b9e634b4420867ea3b402cb858", package = "cultcache-rs" } diff --git a/crates/odin-daemon/src/main.rs b/crates/odin-daemon/src/main.rs index 00067fe..be6ebec 100644 --- a/crates/odin-daemon/src/main.rs +++ b/crates/odin-daemon/src/main.rs @@ -5,6 +5,8 @@ use std::net::{SocketAddr, UdpSocket}; use std::os::fd::{FromRawFd, RawFd}; use std::path::{Path, PathBuf}; use std::rc::Rc; +use std::sync::Arc; +use std::sync::atomic::{AtomicBool, Ordering}; use std::thread; use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; @@ -59,7 +61,10 @@ const ACTIVATION_SIGNER_FD_NAME: &str = IDUNN_RUNTIME_ACTIVATION_CREDENTIAL_NAME const PROVIDER_SIGNER_FD_NAME: &str = "gamecult-runtime-presence-identity"; const SYSTEMD_LISTEN_FDS_START: RawFd = 3; -const BOOTSTRAP_LEASE_TIMEOUT: Duration = Duration::from_secs(60); +// Long enough for Idunn to warm, fence the incumbent, and grant the lease. A +// candidate that never hears back is cleaned up by Idunn's own abort; this +// only bounds how long it sits idle first. +const BOOTSTRAP_LEASE_TIMEOUT: Duration = Duration::from_secs(300); const SELF_PUBLISH_TIMEOUT: Duration = Duration::from_secs(6); const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5); const PROJECTION_REFRESH_INTERVAL: Duration = Duration::from_millis(250); @@ -554,8 +559,22 @@ fn main() -> Result<()> { CultMeshRudpDocumentServerOptions::default(), )?; + // Idunn runs this process as PID 1 of its own PID namespace, and a + // namespace init ignores every signal it has not caught. Without this, + // a stop is a ninety-second wait for SIGKILL, which is what fencing the + // incumbent during a deployment costs its candidate. + let stopping = Arc::new(AtomicBool::new(false)); + for signal in [signal_hook::consts::SIGTERM, signal_hook::consts::SIGINT] { + signal_hook::flag::register(signal, Arc::clone(&stopping)) + .context("registering Odin's stop signal handler")?; + } + let bootstrap_started = Instant::now(); while !state.borrow_mut().try_activate()? { + if stopping.load(Ordering::Relaxed) { + eprintln!("Odin stopping before activation on request"); + return Ok(()); + } let progressed = poll_server(&mut server)?; ensure!( bootstrap_started.elapsed() < BOOTSTRAP_LEASE_TIMEOUT, @@ -575,6 +594,10 @@ fn main() -> Result<()> { let mut last_heartbeat = Instant::now(); let mut last_projection_refresh = Instant::now(); loop { + if stopping.load(Ordering::Relaxed) { + eprintln!("Odin stopping on request"); + return Ok(()); + } let progressed = poll_server(&mut server)?; if last_projection_refresh.elapsed() >= PROJECTION_REFRESH_INTERVAL { state.borrow_mut().refresh_all_correlations()?;