From 090bf0d7e2d63029be49af63e45d4a5ced8bbff3 Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Mon, 9 Nov 2026 15:32:24 +0100 Subject: [PATCH 1/2] fix: every stop followed by a start holds the daemon, not only a restart A candidate of a service without a proxy takes over by a stop and a start (`take_over`), from the watcher, with no request holding the daemon: when the idle check ran in the gap, the daemon ended and the start ran in a daemon on its way out (`an_edit_while_exited_follows_the_restart`, Windows CI, twice). #481 guarded `restart` alone; `switching` is now the one guard, used by restart, take-over, relaunch and the hot-reload switch. Bug-Class: race-on-idle Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 10 +++++ .../src/supervisor/candidate.rs | 27 ++++++++----- .../src/supervisor/lifecycle.rs | 2 + crates/devstack-daemon/src/supervisor/mod.rs | 38 +++++++++++++++++++ .../devstack-daemon/src/supervisor/replace.rs | 14 ++----- 5 files changed, 71 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a29592b..562bdca4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,16 @@ and listed with their assets on the `devstack status` and the dashboard say the file changed. For the main tree, `status` now says that its daemon stays while lanes run. +### Fixed + +- **A candidate taking over no longer ends the daemon.** A service without + a proxy takes a new build by a stop and a start; when the daemon looked + whether anything still ran in the gap between the two, it ended, and the + start ran in a daemon on its way out (the same gap as the restart fixed + in 0.42.0, seen on Windows in CI). Every stop followed by a start now + holds the daemon: a restart, a candidate taking over, a relaunch, hot + reload switched on or off. + ## [0.42.0] - 2026-11-06 A pool's skill can now speak at the end of the work: a `lane-stop` diff --git a/crates/devstack-daemon/src/supervisor/candidate.rs b/crates/devstack-daemon/src/supervisor/candidate.rs index b63b2d4e..c1c71647 100644 --- a/crates/devstack-daemon/src/supervisor/candidate.rs +++ b/crates/devstack-daemon/src/supervisor/candidate.rs @@ -300,6 +300,9 @@ impl Supervisor { return self.replace(name, svc, Some(artifact)); } self.set_candidate(name, None); + // From the watcher, not a request: nothing else holds the daemon + // between the stop and the start. + let _switching = self.switching(name); self.stop(name)?; self.start_with(name, Some(artifact)) } @@ -595,20 +598,24 @@ 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. + /// A stop followed by a start keeps the daemon: in the gap nothing of + /// the service runs, and the daemon must not end there (#481 for a + /// restart; a candidate taking over in place ended it the same way). #[test] - fn a_restart_under_way_counts_as_running() { + fn a_switch_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; + { + let _outer = sup.switching("a"); + { + let _inner = sup.switching("a"); + assert!(sup.runs_anything(), "between its stop and start"); + } + assert!(sup.runs_anything(), "the outer one still"); + assert!(sup.restart_under_way("a")); + } assert!(!sup.runs_anything()); + assert!(!sup.restart_under_way("a")); } /// A change reported after a restart began waits for the restart, past diff --git a/crates/devstack-daemon/src/supervisor/lifecycle.rs b/crates/devstack-daemon/src/supervisor/lifecycle.rs index f1407445..2edf86a0 100644 --- a/crates/devstack-daemon/src/supervisor/lifecycle.rs +++ b/crates/devstack-daemon/src/supervisor/lifecycle.rs @@ -479,6 +479,7 @@ impl Supervisor { "hot_reload", serde_json::json!({ "service": name, "on": on }), ); + let _switching = self.switching(name); self.stop(name)?; self.start(name) } @@ -508,6 +509,7 @@ impl Supervisor { .map(|id| (self.layout.artifact(name, &id), id)) .filter(|(dir, _)| dir.is_dir()) .map(|(dir, id)| (id, dir)); + let _switching = self.switching(name); self.stop(name)?; self.start_with(name, artifact) } diff --git a/crates/devstack-daemon/src/supervisor/mod.rs b/crates/devstack-daemon/src/supervisor/mod.rs index 15a93a2d..ca2add5d 100644 --- a/crates/devstack-daemon/src/supervisor/mod.rs +++ b/crates/devstack-daemon/src/supervisor/mod.rs @@ -332,6 +332,26 @@ fn start_fields( Some(m) } +/// A stop followed by a start under way ([`Supervisor::switching`]). +pub(crate) struct Switching<'a> { + sup: &'a Supervisor, + name: String, +} + +impl Drop for Switching<'_> { + fn drop(&mut self) { + if let Some(n) = self + .sup + .restarts_under_way + .lock() + .unwrap() + .get_mut(&self.name) + { + *n = n.saturating_sub(1); + } + } +} + /// Hash of the stack file, line endings ignored (a checkout may flip them). fn stack_file_hash(path: &Path) -> Option { let bytes = std::fs::read(path).ok()?; @@ -1193,6 +1213,24 @@ impl Supervisor { .is_some_and(|s| s.view.status.is_active()) } + /// `name` is stopped to be started again (a restart, a candidate that + /// takes over in place, a relaunch): until the guard is dropped it counts + /// as running, so the daemon does not end in the gap between the stop + /// and the start (ADR-0095; #481 for `restart`, the others since), and a + /// change seen meanwhile waits for it (#233). + pub(crate) fn switching(&self, name: &str) -> Switching<'_> { + *self + .restarts_under_way + .lock() + .unwrap() + .entry(name.to_string()) + .or_default() += 1; + Switching { + sup: self, + name: name.to_string(), + } + } + /// Is a `restart` of `name` under way (stopping, starting, or running /// the jobs it comes after)? pub(crate) fn restart_under_way(&self, name: &str) -> bool { diff --git a/crates/devstack-daemon/src/supervisor/replace.rs b/crates/devstack-daemon/src/supervisor/replace.rs index a00ba67d..beee2114 100644 --- a/crates/devstack-daemon/src/supervisor/replace.rs +++ b/crates/devstack-daemon/src/supervisor/replace.rs @@ -38,16 +38,10 @@ impl Supervisor { self.restarting.lock().unwrap().insert(name.to_string()); self.set_front(name, crate::tcpfwd::FrontState::Hold(hold)); } - *self - .restarts_under_way - .lock() - .unwrap() - .entry(name.to_string()) - .or_default() += 1; - let result = self.restart_inner(name); - if let Some(n) = self.restarts_under_way.lock().unwrap().get_mut(name) { - *n -= 1; - } + let result = { + let _switching = self.switching(name); + self.restart_inner(name) + }; if fronted { self.restarting.lock().unwrap().remove(name); if result.is_err() && !self.service_running(name) { From 5f2fbcd6a80ecd6bf667c09049cec4f6d759f056 Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Mon, 9 Nov 2026 15:33:37 +0100 Subject: [PATCH 2/2] docs: one Fixed section Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 562bdca4..a9861d56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,8 +49,6 @@ and listed with their assets on the `devstack status` and the dashboard say the file changed. For the main tree, `status` now says that its daemon stays while lanes run. -### Fixed - - **A candidate taking over no longer ends the daemon.** A service without a proxy takes a new build by a stop and a start; when the daemon looked whether anything still ran in the gap between the two, it ended, and the