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 <noreply@anthropic.com>
This commit is contained in:
parent
e1a399f84d
commit
b8ef6c62ae
3 changed files with 46 additions and 1 deletions
21
Cargo.lock
generated
21
Cargo.lock
generated
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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" }
|
||||
|
|
|
|||
|
|
@ -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()?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue