Skip to content

Commit

Permalink
While start the shim fail, ensure the socket file has been remove
Browse files Browse the repository at this point in the history
Discovered socket file leak when set_cgroup_ond_oom_store execution failed

Signed-off-by: jokemanfire <[email protected]>
  • Loading branch information
jokemanfire committed Feb 5, 2025
1 parent 9d9cc05 commit 993cc51
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions crates/shim/src/asynchronous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,21 @@ pub async fn spawn(opts: StartOpts, grouping: &str, vars: Vec<(&str, &str)>) ->
command.arg("-debug");
}
command.envs(vars);

let _child = command.spawn().map_err(io_error!(e, "spawn shim"))?;
// if fail we should remove socket
let result = command.spawn().map_err(io_error!(e, "spawn shim"));
if result.is_err() {
remove_socket(&address).await?;
}
let _child = result?;
// if fail we should remove socket
#[cfg(target_os = "linux")]
crate::cgroup::set_cgroup_and_oom_score(_child.id())?;
Ok(address)
match crate::cgroup::set_cgroup_and_oom_score(_child.id()) {
Ok(_) => Ok(address),
Err(error) => {
remove_socket(&address).await?;
Err(error)
}
}
}

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

0 comments on commit 993cc51

Please sign in to comment.