From a791b46309a5dcb08def70aa43f377d211fe67a6 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Sun, 20 Sep 2026 00:47:39 -0700 Subject: [PATCH] fix(vmm): persist guest events outside the global state lock --- dstack/vmm/src/app.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/dstack/vmm/src/app.rs b/dstack/vmm/src/app.rs index c63fcff74..5b92c0198 100644 --- a/dstack/vmm/src/app.rs +++ b/dstack/vmm/src/app.rs @@ -1512,6 +1512,7 @@ impl App { error!("Event body too large, skipping"); return Ok(()); } + // Persist outside the global state lock so disk I/O does not stall other VMs. let mut state = self.lock(); let Some(vm) = state.vms.values_mut().find(|vm| vm.config.cid == cid) else { bail!("VM not found"); @@ -1528,26 +1529,23 @@ impl App { vm.state.events.pop_front(); } match event { - "boot.progress" => { - vm.state.boot_progress = body; - } - "boot.error" => { - vm.state.boot_error = body; - } + "boot.progress" => vm.state.boot_progress = body, + "boot.error" => vm.state.boot_error = body, "shutdown.progress" => { - if body == "powering off" { - self.set_started(&vm.config.manifest.id, false)?; - } + let powering_off = body == "powering off"; vm.state.shutdown_progress = body; + let id = vm.config.manifest.id.clone(); + drop(state); + if powering_off { + self.set_started(&id, false)?; + } } "instance.info" => { let workdir = VmWorkDir::new(vm.config.workdir.clone()); - let instancd_info_path = workdir.instance_info_path(); - safe_write::safe_write(&instancd_info_path, &body)?; - } - _ => { - error!("Guest reported unknown event: {event}"); + drop(state); + safe_write::safe_write(workdir.instance_info_path(), &body)?; } + _ => error!("Guest reported unknown event: {event}"), } Ok(()) }