From 58ebc63d110406b9367df5c17cf15ea22cf9f14d Mon Sep 17 00:00:00 2001 From: jatmn Date: Sat, 5 Dec 2026 15:34:10 -0800 Subject: [PATCH 1/2] Synchronize updater child-exit and health handoff tests --- crates/updater/src/controller_tests.rs | 632 +++++++++++-------------- crates/updater/src/main.rs | 53 ++- 2 files changed, 327 insertions(+), 358 deletions(-) diff --git a/crates/updater/src/controller_tests.rs b/crates/updater/src/controller_tests.rs index 63740bc3..9244fda5 100644 --- a/crates/updater/src/controller_tests.rs +++ b/crates/updater/src/controller_tests.rs @@ -345,6 +345,8 @@ fn controller( maintenance: None, health: None, health_bind: None, + control_read_entered: None, + health_handoff: None, exit_control_gate: None, readiness_error_gate: None, before_idle_gate: None, @@ -4066,6 +4068,64 @@ async fn assert_launcher_health(addr: std::net::SocketAddr, reason: &str) { } } +/// A ready future can win Tokio's timeout even when its last poll returned late. +async fn within_restart_budget(budget: Duration, work: impl Future) -> T { + let started = Instant::now(); + let value = tokio::time::timeout(budget, work) + .await + .expect("restart deadline expired"); + assert!( + started.elapsed() < budget, + "restart completed after {budget:?}" + ); + value +} + +fn observe_once( + slot: &mut Option>, +) -> tokio::sync::oneshot::Receiver<()> { + let (send, receive) = tokio::sync::oneshot::channel(); + *slot = Some(send); + receive +} + +async fn assert_health_after( + event: tokio::sync::oneshot::Receiver<()>, + addr: std::net::SocketAddr, +) { + event.await.expect("supervisor dropped the health handoff"); + assert!( + read_launcher_health(addr).await, + "launcher did not answer /health" + ); +} + +/// A readable pidfd signals exit without consuming wait status. The synchronous +/// wait also lets current-thread tests keep the launcher watcher unscheduled. +fn wait_for_pidfd_exit(pidfd: &std::fs::File, limit: Duration) { + let started = Instant::now(); + let mut fd = libc::pollfd { + fd: pidfd.as_raw_fd(), + events: libc::POLLIN, + revents: 0, + }; + loop { + let remaining = limit + .checked_sub(started.elapsed()) + .expect("child exit deadline expired"); + // Round up to the millisecond used by poll(2). + let millis = remaining.as_nanos().div_ceil(1_000_000).try_into().unwrap(); + // SAFETY: fd describes one live pollfd and the borrowed pidfd remains open. + let rc = unsafe { libc::poll(&mut fd, 1, millis) }; + if rc < 0 && std::io::Error::last_os_error().kind() == std::io::ErrorKind::Interrupted { + continue; + } + assert_eq!(rc, 1, "pidfd did not report exit: {rc}"); + assert_ne!(fd.revents & libc::POLLIN, 0, "unexpected pidfd events"); + break; + } +} + #[tokio::test] async fn exited_bot_serves_health_while_tick_database_is_stalled() { let root = std::env::temp_dir().join(format!("health-stall-{:032x}", rand::random::())); @@ -4082,13 +4142,9 @@ async fn exited_bot_serves_health_while_tick_database_is_stalled() { .unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); let bound = root.join("health-bound-health-child"); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("child never bound health"); let addr: std::net::SocketAddr = tokio::fs::read_to_string(&bound) .await .unwrap() @@ -4127,23 +4183,21 @@ async fn exited_bot_serves_health_while_tick_database_is_stalled() { })); ready.await.unwrap(); } - let tick = tokio::spawn(async move { + let control_read = observe_once(&mut bot.control_read_entered); + let mut tick = tokio::spawn(async move { let result = bot.tick().await; (bot, result) }); tokio::time::timeout(POLL, async { - loop { - if tokio::net::TcpStream::connect(addr).await.is_ok() { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } + control_read.await.unwrap(); assert_launcher_health(addr, "not ready").await; }) .await .expect("health remained unbound behind the stalled database step"); - tokio::time::sleep(POLL).await; - assert!(!tick.is_finished(), "database step must still be stalled"); + assert!( + tokio::time::timeout(POLL, &mut tick).await.is_err(), + "database step must remain stalled for a poll" + ); assert_launcher_health(addr, "not ready").await; drop(releases); for blocker in blockers { @@ -4195,13 +4249,9 @@ async fn exited_bot_serves_health_while_tick_database_is_stalled() { "control error must not skip the local restart" ); assert!(bot.health.is_none(), "live child owns health"); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("restarted child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("restarted child never bound health"); assert_eq!( tokio::net::TcpListener::bind(addr) .await @@ -4216,13 +4266,9 @@ async fn exited_bot_serves_health_while_tick_database_is_stalled() { tokio::fs::remove_file(&bound).await.unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); assert!(bot.health.is_none()); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("replacement never acquired health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("replacement never acquired health"); assert_eq!( tokio::net::TcpListener::bind(addr) .await @@ -4255,13 +4301,9 @@ async fn running_bot_exit_during_stalled_tick_restores_health() { .unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); let bound = root.join("health-bound-health-live"); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("child never bound health"); let addr: std::net::SocketAddr = tokio::fs::read_to_string(&bound) .await .unwrap() @@ -4274,9 +4316,8 @@ async fn running_bot_exit_during_stalled_tick_restores_health() { bot.idle().await.unwrap(); assert!(bot.health.is_none(), "live child owns health"); - // Hold every pool permit before the tick. One current-thread yield then - // polls tick() through its live-child check and parks it on the database - // acquire, before this test is allowed to exit the child. + // On this current-thread runtime the test resumes after the tick reaches + // its upgrade read and parks on the two occupied pool connections. let mut releases = Vec::new(); let mut blockers = Vec::new(); for _ in 0..2 { @@ -4295,11 +4336,16 @@ async fn running_bot_exit_during_stalled_tick_restores_health() { })); ready.await.unwrap(); } + let handoff = observe_once(&mut bot.health_handoff); + let control_read = observe_once(&mut bot.control_read_entered); let tick = tokio::spawn(async move { let result = bot.tick().await; (bot, result) }); - tokio::task::yield_now().await; + tokio::time::timeout(POLL, control_read) + .await + .unwrap() + .unwrap(); assert!( !tick.is_finished(), "database step must stall while the child is still running" @@ -4309,19 +4355,9 @@ async fn running_bot_exit_during_stalled_tick_restores_health() { "launcher must not own health before the live child exits" ); publish_exit_code(root.join("exit-code-health-live"), 1).await; - let recovered = tokio::time::timeout(POLL, async { - loop { - if launcher_health_responds(addr).await { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await; - assert!( - recovered.is_ok(), - "health remained unbound after the child exited during the stalled database step" - ); + tokio::time::timeout(POLL, assert_health_after(handoff, addr)) + .await + .expect("health remained unbound after the child exited during the stalled database step"); assert_launcher_health(addr, "not ready").await; assert!( !tick.is_finished(), @@ -4392,13 +4428,9 @@ async fn rejected_token_exit_during_stalled_tick_keeps_hold_reason() { .unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); let bound = root.join("health-bound-health-token"); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("child never bound health"); let addr: std::net::SocketAddr = tokio::fs::read_to_string(&bound) .await .unwrap() @@ -4428,11 +4460,16 @@ async fn rejected_token_exit_during_stalled_tick_keeps_hold_reason() { })); ready.await.unwrap(); } + let handoff = observe_once(&mut bot.health_handoff); + let control_read = observe_once(&mut bot.control_read_entered); let tick = tokio::spawn(async move { let result = bot.tick().await; (bot, result) }); - tokio::task::yield_now().await; + tokio::time::timeout(POLL, control_read) + .await + .unwrap() + .unwrap(); assert!( !tick.is_finished(), "database step must stall while the child is running" @@ -4442,16 +4479,9 @@ async fn rejected_token_exit_during_stalled_tick_keeps_hold_reason() { jmodguard::launcher_child::DISCORD_TOKEN_REJECTED_EXIT_CODE, ) .await; - tokio::time::timeout(POLL, async { - loop { - if launcher_health_responds(addr).await { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("health remained unbound after token rejection during the stalled step"); + tokio::time::timeout(POLL, assert_health_after(handoff, addr)) + .await + .expect("health remained unbound after token rejection during the stalled step"); assert_launcher_health(addr, "discord token rejected").await; assert!(!tick.is_finished()); drop(releases); @@ -4493,13 +4523,9 @@ async fn token_exit_before_idle_keeps_health_during_stalled_control() { .unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); let bound = root.join(format!("health-bound-{name}")); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("child never bound health"); let addr: std::net::SocketAddr = tokio::fs::read_to_string(&bound) .await .unwrap() @@ -4518,8 +4544,9 @@ async fn token_exit_before_idle_keeps_health_during_stalled_control() { .child .id() .expect("live child pid"); + let (entered, reached) = tokio::sync::oneshot::channel(); let (release_gate, gate) = tokio::sync::oneshot::channel(); - bot.before_idle_gate = Some(gate); + bot.before_idle_gate = Some((entered, gate)); let control = bot.control.clone(); let mut releases = Vec::new(); @@ -4540,11 +4567,12 @@ async fn token_exit_before_idle_keeps_health_during_stalled_control() { })); ready.await.unwrap(); } + let handoff = observe_once(&mut bot.health_handoff); let tick = tokio::spawn(async move { let result = bot.tick().await; (bot, result) }); - tokio::task::yield_now().await; + tokio::time::timeout(POLL, reached).await.unwrap().unwrap(); assert!( !tick.is_finished(), "tick must wait after the hold check while the child is still alive" @@ -4558,33 +4586,23 @@ async fn token_exit_before_idle_keeps_health_during_stalled_control() { jmodguard::launcher_child::DISCORD_TOKEN_REJECTED_EXIT_CODE, ) .await; - tokio::time::timeout(POLL, async { - loop { - if child_is_zombie(pid) { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("child did not exit 78 before idle"); - let stalled = tokio::spawn(async move { control.component("bot").await }); - tokio::task::yield_now().await; + wait_for_pidfd_exit(&open_pidfd(pid).unwrap(), POLL); + assert!(child_is_zombie(pid)); + let mut read = Box::pin(async move { control.component("bot").await }); + assert!( + std::future::poll_fn(|cx| std::task::Poll::Ready(read.as_mut().poll(cx))) + .await + .is_pending() + ); + let stalled = tokio::spawn(read); assert!( !stalled.is_finished(), "control read must be stalled before idle runs" ); release_gate.send(()).unwrap(); - tokio::time::timeout(POLL, async { - loop { - if launcher_health_responds(addr).await { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("health stayed down after exit 78 while the control read was stalled"); + tokio::time::timeout(POLL, assert_health_after(handoff, addr)) + .await + .expect("health stayed down after exit 78 while the control read was stalled"); assert!( !stalled.is_finished(), "control read must still be stalled after health returns" @@ -4645,6 +4663,18 @@ async fn block_sqlite_pool( (releases, blockers) } +/// Move the fixture clock to the last instant before the first retry is due. +fn advance_to_before_crash_retry(bot: &mut Supervisor) -> Instant { + let retry_at = bot.restart.crash_clock.unwrap() + POLL; + assert_eq!( + bot.restart.not_before, + Some(retry_at), + "first crash must defer restart by one poll" + ); + bot.restart.crash_clock = Some(retry_at - Duration::from_nanos(1)); + retry_at +} + /// Exit 1 lands after `idle` saw the child alive and before the pre-control hold /// check. That check reaps it. `/health` has to answer within one poll while the /// SQLite pool is still blocked, and the exit is counted once for restart. @@ -4664,14 +4694,11 @@ async fn ordinary_exit_after_idle_keeps_health_during_stalled_control() { .await .unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); + bot.restart.crash_clock = Some(bot.running.as_ref().unwrap().started); let bound = root.join(format!("health-bound-{name}")); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("child never bound health"); let addr: std::net::SocketAddr = tokio::fs::read_to_string(&bound) .await .unwrap() @@ -4690,14 +4717,17 @@ async fn ordinary_exit_after_idle_keeps_health_during_stalled_control() { .child .id() .expect("live child pid"); + let (entered, reached) = tokio::sync::oneshot::channel(); let (release_gate, gate) = tokio::sync::oneshot::channel(); - bot.after_idle_gate = Some(gate); + bot.after_idle_gate = Some((entered, gate)); let (releases, blockers) = block_sqlite_pool(&db).await; + let handoff = observe_once(&mut bot.health_handoff); + let control_read = observe_once(&mut bot.control_read_entered); let tick = tokio::spawn(async move { let result = bot.tick().await; (bot, result) }); - tokio::task::yield_now().await; + tokio::time::timeout(POLL, reached).await.unwrap().unwrap(); assert!( !tick.is_finished(), "tick must wait after idle while the child is still alive" @@ -4708,27 +4738,16 @@ async fn ordinary_exit_after_idle_keeps_health_during_stalled_control() { ); let exit = root.join(format!("exit-code-{name}")); publish_exit_code(&exit, 1).await; - tokio::time::timeout(POLL, async { - loop { - if child_is_zombie(pid) { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("child did not exit 1 before the pre-control hold check"); + wait_for_pidfd_exit(&open_pidfd(pid).unwrap(), POLL); + assert!(child_is_zombie(pid)); release_gate.send(()).unwrap(); - tokio::time::timeout(POLL, async { - loop { - if launcher_health_responds(addr).await { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("health stayed down after exit 1 while the database was blocked"); + tokio::time::timeout(POLL, assert_health_after(handoff, addr)) + .await + .expect("health stayed down after exit 1 while the database was blocked"); + tokio::time::timeout(POLL, control_read) + .await + .unwrap() + .unwrap(); assert!( !tick.is_finished(), "database must still be blocked after health returns" @@ -4747,7 +4766,7 @@ async fn ordinary_exit_after_idle_keeps_health_during_stalled_control() { ); assert_launcher_health(addr, "not ready").await; assert!(bot.restart_intent == RestartIntent::Retry); - assert!(bot.restart.waiting(Instant::now())); + let retry_at = advance_to_before_crash_retry(&mut bot); assert_eq!(bot.restart.failures, 1); assert!(bot.running.is_none()); assert_eq!(child_start_count(&root, name), 1); @@ -4757,26 +4776,14 @@ async fn ordinary_exit_after_idle_keeps_health_during_stalled_control() { 1, "backoff must hold the restart" ); - bot.restart.not_before = None; + bot.restart.crash_clock = Some(retry_at); tokio::fs::remove_file(&exit).await.unwrap(); tokio::fs::remove_file(&bound).await.unwrap(); - let marker_changes = watch_fixture_changes(&root, libc::IN_MOVED_TO).unwrap(); bot.tick().await.unwrap(); // The child records its start before publishing the health-bound marker. - tokio::time::timeout(POLL, async { - use std::io::Read; - let mut events = [0; 4096]; - while !bound.exists() { - marker_changes - .async_io(tokio::io::Interest::READABLE, |mut file| { - file.read(&mut events) - }) - .await - .unwrap(); - } - }) - .await - .expect("restarted child never published its health-bound marker"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("restarted child never published its health-bound marker"); assert_eq!(child_start_count(&root, name), 2); bot.stop_application().await.unwrap(); bot.end_idle().await.unwrap(); @@ -4802,14 +4809,11 @@ async fn ordinary_exit_during_blocked_pool_restores_health() { .await .unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); + bot.restart.crash_clock = Some(bot.running.as_ref().unwrap().started); let bound = root.join(format!("health-bound-{name}")); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("child never bound health"); let addr: std::net::SocketAddr = tokio::fs::read_to_string(&bound) .await .unwrap() @@ -4829,11 +4833,16 @@ async fn ordinary_exit_during_blocked_pool_restores_health() { .id() .expect("live child pid"); let (releases, blockers) = block_sqlite_pool(&db).await; + let handoff = observe_once(&mut bot.health_handoff); + let control_read = observe_once(&mut bot.control_read_entered); let tick = tokio::spawn(async move { let result = bot.tick().await; (bot, result) }); - tokio::task::yield_now().await; + tokio::time::timeout(POLL, control_read) + .await + .unwrap() + .unwrap(); assert!( !tick.is_finished(), "database step must stall while the child is still running" @@ -4847,16 +4856,9 @@ async fn ordinary_exit_during_blocked_pool_restores_health() { "launcher must not own health before the live child exits" ); publish_exit_code(root.join(format!("exit-code-{name}")), 1).await; - tokio::time::timeout(POLL, async { - loop { - if launcher_health_responds(addr).await { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("health stayed down after exit 1 while the database was blocked"); + tokio::time::timeout(POLL, assert_health_after(handoff, addr)) + .await + .expect("health stayed down after exit 1 while the database was blocked"); assert!( !tick.is_finished(), "database must still be blocked after health returns" @@ -4875,7 +4877,11 @@ async fn ordinary_exit_during_blocked_pool_restores_health() { ); assert_launcher_health(addr, "not ready").await; assert!(bot.restart_intent == RestartIntent::Retry); - assert!(bot.restart.waiting(Instant::now())); + advance_to_before_crash_retry(&mut bot); + assert!( + !bot.tick().await.unwrap(), + "crash backoff must hold the restart" + ); assert_eq!(bot.restart.failures, 1); assert!(bot.running.is_none()); assert_eq!(child_start_count(&root, name), 1); @@ -4907,13 +4913,9 @@ async fn unsaved_failure_receipt_restarts_child_while_database_is_stalled() { .unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); let bound = root.join("health-bound-health-receipt"); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("child never bound health"); let addr: std::net::SocketAddr = tokio::fs::read_to_string(&bound) .await .unwrap() @@ -4944,8 +4946,9 @@ async fn unsaved_failure_receipt_restarts_child_while_database_is_stalled() { )), launcher: None, }); - bot.activation_receipts.schedule = - ReceiptSchedule::After(Instant::now() + Duration::from_secs(60)); + // Use the receipt policy's capped one-minute delay. + bot.activation_receipts.attempt = 6; + bot.activation_receipts.defer(); assert!( !bot.tick().await.unwrap(), "crash backoff still holds the restart" @@ -4975,23 +4978,24 @@ async fn unsaved_failure_receipt_restarts_child_while_database_is_stalled() { })); ready.await.unwrap(); } - let started = Instant::now(); - let tick = tokio::spawn(async move { + let control_read = observe_once(&mut bot.control_read_entered); + let mut tick = Box::pin(async move { let result = bot.tick().await; (bot, result) }); - tokio::time::timeout(POLL, async { - while !bound.exists() { - assert!( - !tick.is_finished(), - "database step finished before the child restarted" - ); - tokio::time::sleep(Duration::from_millis(10)).await; + within_restart_budget(POLL, async { + tokio::select! { + biased; + _ = &mut tick => panic!("database step finished before the child restarted"), + () = wait_for_marker(&bound) => {} } }) - .await - .expect("child was not restarted while the receipt database call was stalled"); - assert!(started.elapsed() < POLL); + .await; + let tick = tokio::spawn(tick); + tokio::time::timeout(POLL, control_read) + .await + .unwrap() + .unwrap(); assert!(!tick.is_finished()); assert_eq!( tokio::net::TcpListener::bind(addr) @@ -5067,24 +5071,18 @@ async fn control_link_unavailable_receipt_restarts_without_waiting() { }); bot.idle().await.unwrap(); assert_launcher_health(addr, "not ready").await; - let started = Instant::now(); - assert!(!bot.tick().await.unwrap()); assert!( - started.elapsed() < Duration::from_secs(2), - "receipt failure delayed restart by {:?}", - started.elapsed() + !within_restart_budget(Duration::from_secs(2), bot.tick()) + .await + .unwrap() ); assert!(bot.running.as_ref().unwrap().child.id().is_some()); assert!(bot.health.is_none()); assert!(bot.pending_failure.is_some()); let bound = root.join("health-bound-health-link"); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("restarted child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("restarted child never bound health"); assert_eq!( tokio::net::TcpListener::bind(addr) .await @@ -5142,14 +5140,11 @@ async fn exit_during_invalid_upgrade( .await .unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); + bot.restart.crash_clock = Some(bot.running.as_ref().unwrap().started); let bound = root.join(format!("health-bound-{name}")); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("child never bound health"); let addr: std::net::SocketAddr = tokio::fs::read_to_string(&bound) .await .unwrap() @@ -5179,11 +5174,16 @@ async fn exit_during_invalid_upgrade( })); ready.await.unwrap(); } + let handoff = observe_once(&mut bot.health_handoff); + let control_read = observe_once(&mut bot.control_read_entered); let tick = tokio::spawn(async move { let result = bot.tick().await; (bot, result) }); - tokio::task::yield_now().await; + tokio::time::timeout(POLL, control_read) + .await + .unwrap() + .unwrap(); assert!( !tick.is_finished(), "database step must stall while the child is still running" @@ -5193,16 +5193,9 @@ async fn exit_during_invalid_upgrade( "launcher must not own health before the live child exits" ); publish_exit_code(root.join(format!("exit-code-{name}")), code).await; - tokio::time::timeout(POLL, async { - loop { - if launcher_health_responds(addr).await { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("health remained unbound after the child exited during the failed read"); + tokio::time::timeout(POLL, assert_health_after(handoff, addr)) + .await + .expect("health remained unbound after the child exited during the failed read"); assert!(!tick.is_finished(), "database step must still be stalled"); drop(releases); for blocker in blockers { @@ -5221,10 +5214,15 @@ async fn control_error_after_exit_during_stall_still_restarts() { let (mut bot, db, root, addr) = exit_during_invalid_upgrade(name, "1").await; assert!(bot.running.is_none()); assert!(bot.restart_intent == RestartIntent::Retry); - assert!(bot.restart.waiting(Instant::now())); + let retry_at = advance_to_before_crash_retry(&mut bot); + assert!( + !bot.tick().await.unwrap(), + "crash backoff must hold the restart" + ); + assert!(bot.running.is_none()); assert_launcher_health(addr, "not ready").await; // Backoff has elapsed. The same control error must not block the restart. - bot.restart.not_before = None; + bot.restart.crash_clock = Some(retry_at); tokio::fs::remove_file(root.join(format!("exit-code-{name}"))) .await .unwrap(); @@ -5234,24 +5232,11 @@ async fn control_error_after_exit_during_stall_still_restarts() { let error = bot.tick().await.unwrap_err(); assert!(error.to_string().contains("expected value"), "{error:#}"); assert!(bot.running.as_ref().unwrap().child.id().is_some()); - // Spawn returns before the child writes its start line. Wait for that - // event instead of assuming the process has been scheduled. - tokio::time::timeout(POLL, async { - while child_start_count(&root, name) < 2 { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("restarted child never published its start"); - assert_eq!(child_start_count(&root, name), 2); let bound = root.join(format!("health-bound-{name}")); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("restarted child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("restarted child never bound health"); + assert_eq!(child_start_count(&root, name), 2); assert!(bot.health.is_none(), "restarted child owns health"); // A later failed read must leave that child running. let error = bot.tick().await.unwrap_err(); @@ -5301,13 +5286,9 @@ async fn standby_child_is_not_restarted_when_control_fails() { .unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); let bound = root.join(format!("health-bound-{name}")); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("child never bound health"); let addr: std::net::SocketAddr = tokio::fs::read_to_string(&bound) .await .unwrap() @@ -5383,15 +5364,11 @@ async fn failed_restart_keeps_launcher_health() { bot.restart_target.as_mut().unwrap().path = child; assert!(!bot.tick().await.unwrap()); assert!(bot.running.as_ref().unwrap().child.id().is_some()); - assert_eq!(child_start_count(&root, "health-re"), 1); let bound = root.join("health-bound-health-re"); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("retried child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("retried child never bound health"); + assert_eq!(child_start_count(&root, "health-re"), 1); assert!(bot.health.is_none(), "retried child owns health"); bot.stop_application().await.unwrap(); assert_launcher_health(addr, "not ready").await; @@ -5418,12 +5395,8 @@ async fn child_exit_without_pidfd_still_binds_health() { }); assert_eq!(unsafe { libc::kill(pid as i32, libc::SIGKILL) }, 0); tokio::time::timeout(POLL, async { - loop { - if launcher_health_responds(addr).await { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } + watch.await.unwrap(); + assert!(read_launcher_health(addr).await); }) .await .expect("pid fallback did not bind health"); @@ -5436,8 +5409,7 @@ async fn child_exit_without_pidfd_still_binds_health() { child_liveness_pid(pid).unwrap(), ChildLiveness::Reaped )); - let _ = cancel.send(()); - let _ = tokio::time::timeout(Duration::from_secs(2), watch).await; + drop(cancel); let serve = bound.lock().unwrap().take(); if let Some(serve) = serve { serve.abort(); @@ -5464,13 +5436,9 @@ async fn supervisor_reap_binds_health_before_stalled_exit_control_read() { .unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); let bound = root.join(format!("health-bound-{name}")); - tokio::time::timeout(POLL, async { - while !bound.exists() { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("child never bound health"); + tokio::time::timeout(POLL, wait_for_marker(&bound)) + .await + .expect("child never bound health"); bot.health_bind = Some(addr.to_string()); bot.arm_child_health_watch(); assert!( @@ -5491,64 +5459,38 @@ async fn supervisor_reap_binds_health_before_stalled_exit_control_read() { .expect("live child pid"); // Block this thread so the watcher cannot observe the exit before the reap. assert_eq!(unsafe { libc::kill(pid as i32, libc::SIGKILL) }, 0); - let deadline = Instant::now() + Duration::from_secs(2); - loop { - if bot - .running + wait_for_pidfd_exit(&open_pidfd(pid).unwrap(), Duration::from_secs(2)); + assert!( + bot.running .as_mut() .unwrap() .child .try_wait() .unwrap() .is_some() - { - break; - } - assert!( - Instant::now() < deadline, - "supervisor did not reap the killed child" - ); - std::thread::sleep(Duration::from_millis(10)); - } - tokio::time::timeout(POLL, async { - loop { - if bot - .child_watch - .as_ref() - .unwrap() - .task - .as_ref() - .unwrap() - .is_finished() - { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("watcher did not exit after the supervisor reaped first"); + ); + let watcher = bot.child_watch.as_mut().unwrap().task.take().unwrap(); + tokio::time::timeout(POLL, watcher) + .await + .expect("watcher did not exit after the supervisor reaped first") + .unwrap(); assert!( !launcher_health_responds(addr).await, "a reaped observation must not bind health" ); let (release, gate) = tokio::sync::oneshot::channel(); - bot.exit_control_gate = Some(gate); + let (entered, reached) = tokio::sync::oneshot::channel(); + bot.exit_control_gate = Some((entered, gate)); + let handoff = observe_once(&mut bot.health_handoff); let normal = tokio::spawn(async move { let result = bot.normal().await; (bot, result) }); - tokio::time::timeout(POLL, async { - loop { - if launcher_health_responds(addr).await { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) + tokio::time::timeout(POLL, assert_health_after(handoff, addr)) .await .expect("health stays unbound after normal() reaps the child and stalls on the error-path upgrade lookup"); + tokio::time::timeout(POLL, reached).await.unwrap().unwrap(); assert!( !normal.is_finished(), "post-exit control read must still be stalled" @@ -5728,7 +5670,8 @@ async fn readiness_recovery_holds_token_exit_between_status_checks() { bot.arm_child_health_watch(); let pid = bot.running.as_ref().unwrap().child.id().unwrap(); let (release, gate) = tokio::sync::oneshot::channel(); - bot.before_idle_gate = Some(gate); + let (entered, mut reached) = tokio::sync::oneshot::channel(); + bot.before_idle_gate = Some((entered, gate)); { let recovery = bot.bind_health_after_observed_exit(); tokio::pin!(recovery); @@ -5739,13 +5682,13 @@ async fn readiness_recovery_holds_token_exit_between_status_checks() { .await .is_pending() ); + reached + .try_recv() + .expect("recovery must be parked before idle"); publish_exit_code_sync(&root.join(format!("exit-code-{name}")), 78); std::fs::remove_file(&hold).unwrap(); - let deadline = Instant::now() + POLL; - while !child_is_zombie(pid) { - assert!(Instant::now() < deadline, "fixture child did not exit"); - std::thread::sleep(Duration::from_millis(10)); - } + wait_for_pidfd_exit(&open_pidfd(pid).unwrap(), POLL); + assert!(child_is_zombie(pid)); release.send(()).unwrap(); // The second check must reap/classify the exit before the watcher runs. tokio::time::timeout(POLL, recovery).await.unwrap().unwrap(); @@ -5771,7 +5714,10 @@ async fn readiness_recovery_keeps_unsaved_candidate_through_auth_retry() { tokio::fs::remove_file(&exit).await.unwrap(); let hold = root.join("hold-desired-bot-ready"); tokio::fs::write(&hold, "hold").await.unwrap(); - bot.restart.auth_retry_at = Some(Instant::now()); + *bot.restart + .auth_retry_at + .as_mut() + .expect("first token hold") -= Duration::from_secs(30 * 60); bot.tick().await.unwrap(); assert!(bot.standby.is_some()); assert!( @@ -5799,13 +5745,8 @@ async fn readiness_recovery_keeps_unsaved_candidate_through_auth_retry() { tokio::time::timeout(POLL, reached).await.unwrap().unwrap(); publish_exit_code(&exit, 78).await; tokio::fs::remove_file(&hold).await.unwrap(); - tokio::time::timeout(POLL, async { - while !child_is_zombie(pid) { - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .unwrap(); + wait_for_pidfd_exit(&open_pidfd(pid).unwrap(), POLL); + assert!(child_is_zombie(pid)); release.send(()).unwrap(); let (mut bot, result) = tokio::time::timeout(POLL, normal).await.unwrap().unwrap(); assert!(bot.restart.auth_admission == AuthAdmission::Held); @@ -5828,7 +5769,10 @@ async fn readiness_recovery_keeps_unsaved_candidate_through_auth_retry() { // Marker writes still fail: retry must use retained candidate/standby, // not restore the installed or baked release. tokio::fs::remove_file(&exit).await.unwrap(); - bot.restart.auth_retry_at = Some(Instant::now()); + *bot.restart + .auth_retry_at + .as_mut() + .expect("second token hold") -= Duration::from_secs(60 * 60); bot.tick().await.unwrap(); assert_eq!( bot.running.as_ref().unwrap().release.as_ref(), @@ -6020,24 +5964,13 @@ async fn settled_exit_keeps_the_backoff_report_ready_already_recorded() { ) .unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); - tokio::time::timeout(Duration::from_secs(2), async { - loop { - if bot - .running - .as_mut() - .unwrap() - .child - .try_wait() - .unwrap() - .is_some() - { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) + tokio::time::timeout( + Duration::from_secs(2), + bot.running.as_mut().unwrap().child.wait(), + ) .await - .expect("child did not exit"); + .expect("child did not exit") + .unwrap(); let error = bot.report_ready().await.unwrap_err(); assert!( error.to_string().contains("application exited"), @@ -6076,17 +6009,14 @@ fn child_liveness_observes_exit_without_reaping() { assert!(child.try_wait().unwrap().is_none()); let rc = unsafe { libc::kill(pid as i32, libc::SIGKILL) }; assert_eq!(rc, 0); - let deadline = Instant::now() + Duration::from_secs(2); - let code = loop { - match child_liveness(pidfd.as_raw_fd()).unwrap() { - ChildLiveness::Exited(code) => break code, - ChildLiveness::Running if Instant::now() < deadline => { - std::thread::sleep(Duration::from_millis(10)); - } - other => panic!("unexpected liveness after kill: {other:?}"), - } - }; - assert!(code.is_none(), "signal death is not an exit code"); + wait_for_pidfd_exit(&pidfd, Duration::from_secs(2)); + assert!( + matches!( + child_liveness(pidfd.as_raw_fd()).unwrap(), + ChildLiveness::Exited(None) + ), + "signal death must be observed without an exit code" + ); assert!( child.try_wait().unwrap().is_some(), "supervisor can still reap" diff --git a/crates/updater/src/main.rs b/crates/updater/src/main.rs index a4dfc02b..38c06148 100644 --- a/crates/updater/src/main.rs +++ b/crates/updater/src/main.rs @@ -105,6 +105,8 @@ struct RestartPolicy { auth_admission: AuthAdmission, failures: u32, not_before: Option, + #[cfg(test)] + crash_clock: Option, auth_failures: u32, auth_retry_at: Option, } @@ -136,6 +138,8 @@ impl RestartPolicy { .saturating_mul(1_u32 << self.failures.min(4)) .min(Duration::from_secs(60)); self.failures = self.failures.saturating_add(1); + #[cfg(test)] + let now = self.crash_clock.unwrap_or(now); self.not_before = Some(now + delay); } @@ -193,6 +197,8 @@ impl RestartPolicy { } fn waiting(&self, now: Instant) -> bool { + #[cfg(test)] + let now = self.crash_clock.unwrap_or(now); self.auth_admission == AuthAdmission::Held || self.not_before.is_some_and(|at| now < at) } } @@ -841,6 +847,12 @@ enum PendingBootMismatch { Clear, } +#[cfg(test)] +type TestGate = ( + tokio::sync::oneshot::Sender<()>, + tokio::sync::oneshot::Receiver<()>, +); + /// Local process ownership plus the durable paired operation. One container per /// role is required; an expired heartbeat never stands in for a reaped child. struct Supervisor { @@ -867,9 +879,14 @@ struct Supervisor { maintenance: Option, health: Option>>, health_bind: Option, + #[cfg(test)] + control_read_entered: Option>, + /// Tests probe the socket after the next idle bind or child watcher returns. + #[cfg(test)] + health_handoff: Option>, /// Test-only stall immediately before the post-exit `upgrade` read. #[cfg(test)] - exit_control_gate: Option>, + exit_control_gate: Option, /// Test-only handoff after a readiness error, before exit recovery. #[cfg(test)] readiness_error_gate: Option<( @@ -878,10 +895,10 @@ struct Supervisor { )>, /// Test-only stall after the opening hold check and before `idle` in tick/recovery. #[cfg(test)] - before_idle_gate: Option>, + before_idle_gate: Option, /// Test-only stall after `idle` and before the pre-control hold check. #[cfg(test)] - after_idle_gate: Option>, + after_idle_gate: Option, /// Test-only handoff immediately before the final spawn checks. #[cfg(test)] before_spawn_gate: Option<( @@ -1517,6 +1534,10 @@ impl Supervisor { self.restart.not_ready_reason(), ), )); + #[cfg(test)] + if let Some(handoff) = self.health_handoff.take() { + let _ = handoff.send(()); + } } Ok(()) } @@ -1534,10 +1555,16 @@ impl Supervisor { let (cancel, cancel_rx) = tokio::sync::oneshot::channel(); let bound = std::sync::Arc::new(std::sync::Mutex::new(None)); let slot = std::sync::Arc::clone(&bound); + #[cfg(test)] + let handoff = self.health_handoff.take(); self.child_watch = Some(ChildExitWatch { cancel: Some(cancel), task: Some(tokio::spawn(async move { watch_child_health(pid, bind, cancel_rx, slot).await; + #[cfg(test)] + if let Some(handoff) = handoff { + let _ = handoff.send(()); + } })), bound, }); @@ -1719,7 +1746,8 @@ impl Supervisor { return Ok(()); } #[cfg(test)] - if let Some(gate) = self.before_idle_gate.take() { + if let Some((entered, gate)) = self.before_idle_gate.take() { + let _ = entered.send(()); let _ = gate.await; } if let Some(child) = self.running.as_mut() { @@ -2760,7 +2788,8 @@ impl Supervisor { return Ok(false); } #[cfg(test)] - if let Some(gate) = self.exit_control_gate.take() { + if let Some((entered, gate)) = self.exit_control_gate.take() { + let _ = entered.send(()); let _ = gate.await; } // After a coordinated migration, never try a previous/baked child. @@ -3070,7 +3099,8 @@ impl Supervisor { // Exit 78 can land after the check above. The test parks here so that // ordering is observable; production falls through with no wait. #[cfg(test)] - if let Some(gate) = self.before_idle_gate.take() { + if let Some((entered, gate)) = self.before_idle_gate.take() { + let _ = entered.send(()); let _ = gate.await; } if (held @@ -3093,7 +3123,8 @@ impl Supervisor { // An ordinary exit can land after idle saw the child alive. The test // parks here so that ordering is observable; production does not wait. #[cfg(test)] - if let Some(gate) = self.after_idle_gate.take() { + if let Some((entered, gate)) = self.after_idle_gate.take() { + let _ = entered.send(()); let _ = gate.await; } // idle reaps exit 78 and leaves the socket unbound, and the reaped pid @@ -3132,6 +3163,10 @@ impl Supervisor { self.flush_startup_receipts().await?; self.flush_pending_failure().await?; self.flush_pending_boot_mismatch().await?; + #[cfg(test)] + if let Some(entered) = self.control_read_entered.take() { + let _ = entered.send(()); + } if let Some(op) = self.control.upgrade().await?.filter(|op| op.phase.active()) { let result = self.pair(&op.id).await; if let Err(error) = result { @@ -3620,6 +3655,10 @@ async fn main() -> Result<()> { health: boot_health, health_bind, #[cfg(test)] + control_read_entered: None, + #[cfg(test)] + health_handoff: None, + #[cfg(test)] exit_control_gate: None, #[cfg(test)] readiness_error_gate: None, From ed51674a5eea4db549d33a1b518536a96d235fdc Mon Sep 17 00:00:00 2001 From: jatmn Date: Sat, 5 Dec 2026 15:54:34 -0800 Subject: [PATCH 2/2] Observe updater child exits without pidfds and drive the pending retry deadline --- crates/updater/src/controller_tests.rs | 75 +++++++++++++++----------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/crates/updater/src/controller_tests.rs b/crates/updater/src/controller_tests.rs index 9244fda5..ff0fbe22 100644 --- a/crates/updater/src/controller_tests.rs +++ b/crates/updater/src/controller_tests.rs @@ -4100,30 +4100,35 @@ async fn assert_health_after( ); } -/// A readable pidfd signals exit without consuming wait status. The synchronous -/// wait also lets current-thread tests keep the launcher watcher unscheduled. -fn wait_for_pidfd_exit(pidfd: &std::fs::File, limit: Duration) { - let started = Instant::now(); - let mut fd = libc::pollfd { - fd: pidfd.as_raw_fd(), - events: libc::POLLIN, - revents: 0, - }; - loop { - let remaining = limit - .checked_sub(started.elapsed()) - .expect("child exit deadline expired"); - // Round up to the millisecond used by poll(2). - let millis = remaining.as_nanos().div_ceil(1_000_000).try_into().unwrap(); - // SAFETY: fd describes one live pollfd and the borrowed pidfd remains open. - let rc = unsafe { libc::poll(&mut fd, 1, millis) }; - if rc < 0 && std::io::Error::last_os_error().kind() == std::io::ErrorKind::Interrupted { - continue; - } - assert_eq!(rc, 1, "pidfd did not report exit: {rc}"); - assert_ne!(fd.revents & libc::POLLIN, 0, "unexpected pidfd events"); - break; - } +/// Observe the owned child's exit without reaping it or yielding the current +/// Tokio thread to the launcher's watcher. P_PID also works without pidfd_open. +fn wait_for_child_exit(pid: u32, limit: Duration) { + let (send, exit) = std::sync::mpsc::channel(); + std::thread::spawn(move || { + let result = loop { + let mut info = std::mem::MaybeUninit::::uninit(); + // SAFETY: info is writable and WNOWAIT leaves this child for its owner. + let rc = unsafe { + libc::waitid( + libc::P_PID, + pid, + info.as_mut_ptr(), + libc::WEXITED | libc::WNOWAIT, + ) + }; + if rc == 0 { + break Ok(()); + } + let error = std::io::Error::last_os_error(); + if error.kind() != std::io::ErrorKind::Interrupted { + break Err(error); + } + }; + let _ = send.send(result); + }); + exit.recv_timeout(limit) + .expect("child exit deadline expired") + .expect("waitid failed to observe the owned child"); } #[tokio::test] @@ -4586,7 +4591,7 @@ async fn token_exit_before_idle_keeps_health_during_stalled_control() { jmodguard::launcher_child::DISCORD_TOKEN_REJECTED_EXIT_CODE, ) .await; - wait_for_pidfd_exit(&open_pidfd(pid).unwrap(), POLL); + wait_for_child_exit(pid, POLL); assert!(child_is_zombie(pid)); let mut read = Box::pin(async move { control.component("bot").await }); assert!( @@ -4738,7 +4743,7 @@ async fn ordinary_exit_after_idle_keeps_health_during_stalled_control() { ); let exit = root.join(format!("exit-code-{name}")); publish_exit_code(&exit, 1).await; - wait_for_pidfd_exit(&open_pidfd(pid).unwrap(), POLL); + wait_for_child_exit(pid, POLL); assert!(child_is_zombie(pid)); release_gate.send(()).unwrap(); tokio::time::timeout(POLL, assert_health_after(handoff, addr)) @@ -4912,6 +4917,7 @@ async fn unsaved_failure_receipt_restarts_child_while_database_is_stalled() { .await .unwrap(); bot.start(&child, &"b".repeat(40), None).await.unwrap(); + bot.restart.crash_clock = Some(bot.running.as_ref().unwrap().started); let bound = root.join("health-bound-health-receipt"); tokio::time::timeout(POLL, wait_for_marker(&bound)) .await @@ -4949,6 +4955,7 @@ async fn unsaved_failure_receipt_restarts_child_while_database_is_stalled() { // Use the receipt policy's capped one-minute delay. bot.activation_receipts.attempt = 6; bot.activation_receipts.defer(); + let retry_at = advance_to_before_crash_retry(&mut bot); assert!( !bot.tick().await.unwrap(), "crash backoff still holds the restart" @@ -4957,7 +4964,7 @@ async fn unsaved_failure_receipt_restarts_child_while_database_is_stalled() { assert_eq!(child_start_count(&root, "health-receipt"), 1); assert_launcher_health(addr, "not ready").await; - bot.restart.not_before = None; + bot.restart.crash_clock = Some(retry_at); tokio::fs::remove_file(&exit).await.unwrap(); tokio::fs::remove_file(&bound).await.unwrap(); let mut releases = Vec::new(); @@ -5459,7 +5466,7 @@ async fn supervisor_reap_binds_health_before_stalled_exit_control_read() { .expect("live child pid"); // Block this thread so the watcher cannot observe the exit before the reap. assert_eq!(unsafe { libc::kill(pid as i32, libc::SIGKILL) }, 0); - wait_for_pidfd_exit(&open_pidfd(pid).unwrap(), Duration::from_secs(2)); + wait_for_child_exit(pid, Duration::from_secs(2)); assert!( bot.running .as_mut() @@ -5687,7 +5694,7 @@ async fn readiness_recovery_holds_token_exit_between_status_checks() { .expect("recovery must be parked before idle"); publish_exit_code_sync(&root.join(format!("exit-code-{name}")), 78); std::fs::remove_file(&hold).unwrap(); - wait_for_pidfd_exit(&open_pidfd(pid).unwrap(), POLL); + wait_for_child_exit(pid, POLL); assert!(child_is_zombie(pid)); release.send(()).unwrap(); // The second check must reap/classify the exit before the watcher runs. @@ -5704,7 +5711,7 @@ async fn readiness_recovery_holds_token_exit_between_status_checks() { tokio::fs::remove_dir_all(root).await.unwrap(); } -#[tokio::test] +#[tokio::test(flavor = "current_thread")] async fn readiness_recovery_keeps_unsaved_candidate_through_auth_retry() { let (root, db, mut bot, candidate, server) = independent_exiting_bot_prepared(78, |bot| bot.fail_rejected_candidate_write = true).await; @@ -5735,6 +5742,10 @@ async fn readiness_recovery_keeps_unsaved_candidate_through_auth_retry() { drop(reserved); bot.health_bind = Some(addr.to_string()); let pid = bot.running.as_ref().unwrap().child.id().unwrap(); + assert!( + bot.child_watch.is_none(), + "normal must handle this exit with no health watcher armed" + ); let (entered, reached) = tokio::sync::oneshot::channel(); let (release, gate) = tokio::sync::oneshot::channel(); bot.readiness_error_gate = Some((entered, gate)); @@ -5745,7 +5756,7 @@ async fn readiness_recovery_keeps_unsaved_candidate_through_auth_retry() { tokio::time::timeout(POLL, reached).await.unwrap().unwrap(); publish_exit_code(&exit, 78).await; tokio::fs::remove_file(&hold).await.unwrap(); - wait_for_pidfd_exit(&open_pidfd(pid).unwrap(), POLL); + wait_for_child_exit(pid, POLL); assert!(child_is_zombie(pid)); release.send(()).unwrap(); let (mut bot, result) = tokio::time::timeout(POLL, normal).await.unwrap().unwrap(); @@ -6009,7 +6020,7 @@ fn child_liveness_observes_exit_without_reaping() { assert!(child.try_wait().unwrap().is_none()); let rc = unsafe { libc::kill(pid as i32, libc::SIGKILL) }; assert_eq!(rc, 0); - wait_for_pidfd_exit(&pidfd, Duration::from_secs(2)); + wait_for_child_exit(pid, Duration::from_secs(2)); assert!( matches!( child_liveness(pidfd.as_raw_fd()).unwrap(),