From f56a7098c59d145fde77bb955b0832bd01c6b232 Mon Sep 17 00:00:00 2001 From: jokemanfire Date: Wed, 5 Feb 2025 14:12:47 +0800 Subject: [PATCH] While start the shim fail, ensure the socket file has been remove Discovered socket file leak when set_cgroup_ond_oom_store execution failed. Signed-off-by: jokemanfire --- crates/shim/src/asynchronous/mod.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/shim/src/asynchronous/mod.rs b/crates/shim/src/asynchronous/mod.rs index b1529af2..4936c6c7 100644 --- a/crates/shim/src/asynchronous/mod.rs +++ b/crates/shim/src/asynchronous/mod.rs @@ -344,10 +344,20 @@ pub async fn spawn(opts: StartOpts, grouping: &str, vars: Vec<(&str, &str)>) -> command.arg("-debug"); } command.envs(vars); + let result = command.spawn().map_err(io_error!(e, "spawn shim")); + let _child = match result { + Ok(child) => child, + Err(e) => { + remove_socket(&address).await?; + return Err(e); + } + }; - let _child = command.spawn().map_err(io_error!(e, "spawn shim"))?; #[cfg(target_os = "linux")] - crate::cgroup::set_cgroup_and_oom_score(_child.id())?; + if let Err(e) = crate::cgroup::set_cgroup_and_oom_score(_child.id()) { + remove_socket(&address).await?; + return Err(e); + } Ok(address) }