From b84211b6d4d10632b258db856114b74acbd8c23c Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Fri, 6 Nov 2026 16:59:47 +0100 Subject: [PATCH] fix: a restart under way keeps the daemon Since the daemon ends with the last tree (ADR-0095), the idle check could fall into a restart's gap: the service stopped, not yet started, nothing else running. On Windows the stop takes seconds, so the daemon ended there and its integration tests failed now and then with "connection refused". A restart under way now counts as running. Bug-Class: a state between two steps of one operation read as the end state Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 6 ++++++ .../devstack-daemon/src/supervisor/candidate.rs | 16 ++++++++++++++++ .../devstack-daemon/src/supervisor/lifecycle.rs | 10 ++++++++++ 3 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d163dcff..570eb764 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,12 @@ and listed with their assets on the ### Fixed +- **A restart no longer ends the stack's daemon.** Since the daemon ends + with the last tree (0.41.0), a restart (`restart_on`, `devstack restart`, + a rebuild) could end it: between the service's stop and its start + nothing ran, and on Windows the stop takes seconds. The daemon ended in + that gap, and the dashboard and the CLI found no daemon until the next + `up`. A restart under way now counts as running. - **Python creating `__pycache__` no longer restarts a dev server** (#463). On Windows the OS reports a folder as modified when an entry appears in it, beside the entry's own event; with a folder in `restart_on` diff --git a/crates/devstack-daemon/src/supervisor/candidate.rs b/crates/devstack-daemon/src/supervisor/candidate.rs index 3388ed40..b63b2d4e 100644 --- a/crates/devstack-daemon/src/supervisor/candidate.rs +++ b/crates/devstack-daemon/src/supervisor/candidate.rs @@ -595,6 +595,22 @@ mod tests { panic!("late past the deadline at every try: {tries:?}"); } + /// A restart under way keeps the daemon: between its stop and its start + /// nothing of the service runs, and the daemon must not end there. + #[test] + fn a_restart_under_way_counts_as_running() { + let (_d, _rt, sup) = two_after_a_job(); + assert!(!sup.runs_anything(), "nothing started"); + *sup.restarts_under_way + .lock() + .unwrap() + .entry("a".into()) + .or_default() += 1; + assert!(sup.runs_anything(), "a restart between its stop and start"); + *sup.restarts_under_way.lock().unwrap().get_mut("a").unwrap() -= 1; + assert!(!sup.runs_anything()); + } + /// A change reported after a restart began waits for the restart, past /// its quiet period: the restart may have built it already (#233). #[test] diff --git a/crates/devstack-daemon/src/supervisor/lifecycle.rs b/crates/devstack-daemon/src/supervisor/lifecycle.rs index ab9b5711..f1407445 100644 --- a/crates/devstack-daemon/src/supervisor/lifecycle.rs +++ b/crates/devstack-daemon/src/supervisor/lifecycle.rs @@ -142,6 +142,16 @@ impl Supervisor { pub fn runs_anything(&self) -> bool { use crate::state::Status; self.upping.load(Ordering::SeqCst) > 0 + // A restart stops before it starts: between the two nothing of + // the service runs, and on Windows the stop takes seconds. The + // daemon ended there, and the start that followed ran in a + // daemon on its way out. + || self + .restarts_under_way + .lock() + .unwrap() + .values() + .any(|n| *n > 0) || self .slots .lock()