Skip to content

Commit ed7af2f

Browse files
committed
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 <[email protected]>
1 parent 1f1e38d commit ed7af2f

File tree

1 file changed

+14
-4
lines changed
  • crates/shim/src/asynchronous

1 file changed

+14
-4
lines changed

crates/shim/src/asynchronous/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,21 @@ pub async fn spawn(opts: StartOpts, grouping: &str, vars: Vec<(&str, &str)>) ->
295295
command.arg("-debug");
296296
}
297297
command.envs(vars);
298-
299-
let _child = command.spawn().map_err(io_error!(e, "spawn shim"))?;
298+
// if fail we should remove socket
299+
let result = command.spawn().map_err(io_error!(e, "spawn shim"));
300+
if result.is_err() {
301+
remove_socket(&address).await?;
302+
}
303+
let _child = result?;
304+
// if fail we should remove socket
300305
#[cfg(target_os = "linux")]
301-
crate::cgroup::set_cgroup_and_oom_score(_child.id())?;
302-
Ok(address)
306+
match crate::cgroup::set_cgroup_and_oom_score(_child.id()) {
307+
Ok(_) => Ok(address),
308+
Err(error) => {
309+
remove_socket(&address).await?;
310+
Err(error)
311+
}
312+
}
303313
}
304314

305315
#[cfg_attr(feature = "tracing", tracing::instrument(skip_all, level = "info"))]

0 commit comments

Comments
 (0)