From 81f9cd068f6c6fb73e41c6c67200616e815d4e75 Mon Sep 17 00:00:00 2001 From: Max Makarov Date: Wed, 3 Jun 2026 13:11:56 +0000 Subject: [PATCH] main: only remove the API socket after a clean run The API socket path was removed unconditionally when the process exited, including on a failed start. On a failed start where another running instance already held the path, that deleted the live instance's socket. Remove the socket only when start_vmm returned Ok, meaning this process owned and bound it. A stale socket left by a crash is cleaned up under the lock by the next start, so dropping the unconditional removal does not leak sockets, and a failed start no longer clobbers a socket owned by another instance. Signed-off-by: Max Makarov Assisted-by: Claude:claude-opus-4-8 [Claude Code] --- cloud-hypervisor/src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cloud-hypervisor/src/main.rs b/cloud-hypervisor/src/main.rs index 750f7aba9..c0d5fd599 100644 --- a/cloud-hypervisor/src/main.rs +++ b/cloud-hypervisor/src/main.rs @@ -902,8 +902,14 @@ fn main() { let vmm_result = start_vmm(&cmd_arguments, &api_socket_path, api_socket_fd); - if let Some(ref p) = api_socket_path { - let _ = std::fs::remove_file(p); + // Remove the socket only when we actually ran (Ok): a failed start may mean + // another instance already holds the path, and removing it would clobber + // that live socket. A stale socket left by a crash is cleared under the lock + // on the next start. + if vmm_result.is_ok() + && let Some(ref api_socket_path) = api_socket_path + { + let _ = std::fs::remove_file(api_socket_path); } let exit_code = match vmm_result {