Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ 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.

- **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`
Expand Down
27 changes: 17 additions & 10 deletions crates/devstack-daemon/src/supervisor/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions crates/devstack-daemon/src/supervisor/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
38 changes: 38 additions & 0 deletions crates/devstack-daemon/src/supervisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<blake3::Hash> {
let bytes = std::fs::read(path).ok()?;
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 4 additions & 10 deletions crates/devstack-daemon/src/supervisor/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down