xonecas.io
8447
Co

conveyor / commit 13a6f38

fix: cleanup VMs of failed runs.

sacenox2026-11-12 13a6f3846cb2b9a4b332366e2dfd93fe7ccc25aa parent 7a222ba

2 files changed

crates/conveyor/src/dispatch.rs+4−1
@@ -5,7 +5,10 @@ use std::time::Duration;
55 const BUSY: [&str; 1] = ["running"];
66
77 pub fn run() -> ! {
8- // A ticket left running by a stopped daemon has no VM any more.
8+ // A ticket left running by a stopped daemon has no worker any more, and its VM goes too.
9+ for e in std::fs::read_dir(paths::vms()).into_iter().flatten().flatten() {
10+ if let Some(name) = e.path().file_stem().and_then(|n| n.to_str()) { crate::vm::reap(name) }
11+ }
912 for p in store::projects() {
1013 for t in store::tickets(&p.slug).into_iter().filter(|t| BUSY.contains(&t.state.as_str())) {
1114 store::set_state(&p.slug, t.id, "failed");
crates/conveyor/src/vm.rs+15−5
@@ -72,15 +72,25 @@ impl Vm {
7272
7373 impl Drop for Vm {
7474 fn drop(&mut self) {
75- if let Ok(pid) = fs::read_to_string(paths::vm_sock(&self.name, "pid")) {
75+ reap(&self.name);
76+ }
77+}
78+
79+/// Stops VM `name` and deletes its sockets and overlay. QEMU daemonizes, so a VM outlives a
80+/// daemon that stopped without dropping it, and keeps its overlay locked.
81+pub fn reap(name: &str) {
82+ if let Ok(pid) = fs::read_to_string(paths::vm_sock(name, "pid")) {
83+ // Only the QEMU running this VM: the pid file can outlive it, and its pid be reused.
84+ let (cmd, arg) = (fs::read(format!("/proc/{}/cmdline", pid.trim())).unwrap_or_default(), format!("-name\0{name}\0"));
85+ if cmd.windows(arg.len()).any(|w| w == arg.as_bytes()) {
7686 let _ = Command::new("kill").arg(pid.trim()).status();
7787 std::thread::sleep(Duration::from_secs(1));
7888 }
79- for k in ["qmp", "qga", "vnc", "pid"] {
80- let _ = fs::remove_file(paths::vm_sock(&self.name, k));
81- }
82- let _ = fs::remove_file(&self.disk);
8389 }
90+ for k in ["qmp", "qga", "vnc", "pid", "verbs"] {
91+ let _ = fs::remove_file(paths::vm_sock(name, k));
92+ }
93+ let _ = fs::remove_file(paths::vms().join(format!("{name}.qcow2")));
8494 }
8595
8696 fn ssh_opts() -> Vec<String> {