From 2507caabc708556f72bd5820da365d48bdad16cb Mon Sep 17 00:00:00 2001 From: 7schmiede Date: Fri, 23 Oct 2026 22:47:05 +0200 Subject: [PATCH 1/2] fix(node): a slot stays busy while any lease's end still takes it down `slot_busy` was a set: when a lane was leased again while the end of its previous lease still ran (Docker, measuring its disk), the second lease's end cleared the mark while the first one's was still under way. A purge then removed the slot, and the first end wrote `slot.json` back: the slot the owner threw away came back (`a_lane_is_leased_admitted_and_synced`, check on ubuntu-latest). The mark is counted now. Co-Authored-By: Claude Opus 5.5 --- crates/devstack-node/src/node.rs | 41 +++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/crates/devstack-node/src/node.rs b/crates/devstack-node/src/node.rs index 01ccc8a2..f49b8789 100644 --- a/crates/devstack-node/src/node.rs +++ b/crates/devstack-node/src/node.rs @@ -259,8 +259,9 @@ struct Inner { /// What each member's blobs take here, once counted. blob_use: Mutex>, /// Slots a lease's end is taking down, or a purge is removing: a new - /// lease of the lane waits for it (ADR-0038 point 1). - slot_busy: Mutex>, + /// lease of the lane waits for it (ADR-0038 point 1). Counted: the end + /// of one lease can still run when the next lease of the lane ends. + slot_busy: Mutex>, /// Slots being removed: no lease is admitted to one until it is gone. slot_purging: Mutex>, /// Whether a member may view a lease (ADR-0040), as the coordinator said @@ -445,6 +446,27 @@ impl Inner { run } + /// One more keeps `slot` busy, until its [`Self::slot_done`]. + fn slot_begin(&self, slot: &str) { + *self + .slot_busy + .lock() + .unwrap() + .entry(slot.to_string()) + .or_default() += 1; + } + + /// One of what keeps `slot` busy is done. + fn slot_done(&self, slot: &str) { + let mut busy = self.slot_busy.lock().unwrap(); + if let Some(n) = busy.get_mut(slot) { + *n -= 1; + if *n == 0 { + busy.remove(slot); + } + } + } + /// Remove slot `slot` and what it holds, unless a lease uses it. fn purge_slot(&self, slot: &str, info: &SlotInfo, why: &str) -> bool { { @@ -455,9 +477,10 @@ impl Inner { return false; } let mut busy = self.slot_busy.lock().unwrap(); - if !busy.insert(slot.to_string()) { + if busy.contains_key(slot) { return false; } + busy.insert(slot.to_string(), 1); self.slot_purging.lock().unwrap().insert(slot.to_string()); } eprintln!( @@ -468,7 +491,7 @@ impl Inner { remove_built_images(slot); self.volume_use.lock().unwrap().remove(slot); self.slot_purging.lock().unwrap().remove(slot); - self.slot_busy.lock().unwrap().remove(slot); + self.slot_done(slot); true } @@ -1081,7 +1104,7 @@ impl Inner { // What it needed is on offer again: the coordinator hears it now. self.changed.notify_one(); if let Some(slot) = &l.slot { - self.slot_busy.lock().unwrap().insert(slot.clone()); + self.slot_begin(slot); } let s = self.clone(); std::thread::spawn(move || { @@ -1114,7 +1137,7 @@ impl Inner { remove_built_images(slot); s.slot_use.lock().unwrap().remove(slot); } - s.slot_busy.lock().unwrap().remove(slot); + s.slot_done(slot); } None => { if l.stack_file.is_some() { @@ -1279,7 +1302,7 @@ async fn slots_purge( tokio::task::spawn_blocking(move || { // The end of its last lease may still be taking it down. let until = Instant::now() + Duration::from_secs(120); - while s2.slot_busy.lock().unwrap().contains(&slot) && Instant::now() < until { + while s2.slot_busy.lock().unwrap().contains_key(&slot) && Instant::now() < until { std::thread::sleep(Duration::from_millis(250)); } if let Some((_, info)) = s2.kept().into_iter().find(|(name, _)| *name == slot) { @@ -2042,7 +2065,7 @@ async fn start( let s2 = s.clone(); let free = tokio::task::spawn_blocking(move || { let until = Instant::now() + Duration::from_secs(120); - while s2.slot_busy.lock().unwrap().contains(&slot) { + while s2.slot_busy.lock().unwrap().contains_key(&slot) { if Instant::now() > until { return false; } @@ -3727,7 +3750,7 @@ pub async fn serve( local_policy, secret, blob_use: Mutex::new(HashMap::new()), - slot_busy: Mutex::new(HashSet::new()), + slot_busy: Mutex::new(HashMap::new()), slot_purging: Mutex::new(HashSet::new()), kept_use: Mutex::new(None), volume_use: Mutex::new(HashMap::new()), From 9a078c8d2479f22766e2f9a1834a39cf021dec06 Mon Sep 17 00:00:00 2001 From: 7schmiede Date: Fri, 23 Oct 2026 22:50:50 +0200 Subject: [PATCH 2/2] docs(changelog): a lane thrown away on a node no longer comes back Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50696038..5d3da087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,14 @@ and listed with their assets on the open window to be reused (`launch_handler`), and names its `id`. `--browser`, `DEVSTACK_BROWSER` and `BROWSER` still win. +### Fixed + +- **A lane its owner threw away on a node no longer comes back.** When a + lane was leased again while the end of its previous lease was still + taking it down, the second lease's end marked the slot free too early: a + purge then removed it, and the first end wrote it back. The node counts + what keeps a slot busy now. + ## [0.21.0] - 2026-10-23 A tray icon on Windows, Linux and macOS, a client of the hub (ADR-0060). A