From 2ed9d7daf43bfed02e3da9c6b26287df78e43b22 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 11:31:20 +1300 Subject: [PATCH] app/: the live listener's probe uses the system clock, not Laravel's (which panics outside the app and killed the listener) --- app/src/live.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/src/live.rs b/app/src/live.rs index a38ccf55..628a758b 100644 --- a/app/src/live.rs +++ b/app/src/live.rs @@ -95,7 +95,7 @@ pub async fn ready(database_url: &str, within: Duration) -> bool { #[must_use] pub fn healthy() -> bool { let last = LAST_PROBE_OK.load(Ordering::Relaxed); - last > 0 && laravel::now().timestamp().as_second() - last < 180 + last > 0 && unix_seconds() - last < 180 } /// This process's listener, for `/status`: `idle` before anything subscribed (nothing to hear yet), `starting` in its @@ -113,7 +113,9 @@ pub fn listener_state() -> &'static str { } } -/// Now, in Unix seconds, from the system clock: the hub starts outside any request, where Laravel's clock isn't set. +/// Now, in Unix seconds, from the system clock: the hub and its probes run in tasks of their own, outside any request, +/// where Laravel's clock isn't set (calling Laravel's `now` there panics: on 3 Dec 2026 that killed the listener on +/// its first probe, and /status read `stale`). Everything about the probe uses this clock. fn unix_seconds() -> i64 { std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) @@ -154,7 +156,7 @@ async fn supervise(url: String, tx: broadcast::Sender, ready: watch::Sen break; } if probe(&url, &tx).await { - LAST_PROBE_OK.store(laravel::now().timestamp().as_second(), Ordering::Relaxed); + LAST_PROBE_OK.store(unix_seconds(), Ordering::Relaxed); } else { tracing::warn!("live updates: a probe didn't come back; restarting the listener"); break; @@ -274,3 +276,20 @@ impl CheckLive { fn schedule(schedule: &mut Schedule) { schedule.job(CheckLive).every_minute().without_overlapping(); } + +#[cfg(test)] +mod tests { + use super::*; + + /// The probe's bookkeeping runs in the listener's own task, outside the application: it must not need Laravel's + /// clock (a plain test has no application, as that task has none). + #[test] + fn probe_health_needs_no_application_context() { + LAST_PROBE_OK.store(unix_seconds(), Ordering::Relaxed); + assert!(healthy()); + LAST_PROBE_OK.store(unix_seconds() - 600, Ordering::Relaxed); + assert!(!healthy()); + LAST_PROBE_OK.store(0, Ordering::Relaxed); + assert!(!healthy()); + } +}