Skip to content

Commit 993cc51

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 9d9cc05 commit 993cc51

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
@@ -344,11 +344,21 @@ pub async fn spawn(opts: StartOpts, grouping: &str, vars: Vec<(&str, &str)>) ->
344344
command.arg("-debug");
345345
}
346346
command.envs(vars);
347-
348-
let _child = command.spawn().map_err(io_error!(e, "spawn shim"))?;
347+
// if fail we should remove socket
348+
let result = command.spawn().map_err(io_error!(e, "spawn shim"));
349+
if result.is_err() {
350+
remove_socket(&address).await?;
351+
}
352+
let _child = result?;
353+
// if fail we should remove socket
349354
#[cfg(target_os = "linux")]
350-
crate::cgroup::set_cgroup_and_oom_score(_child.id())?;
351-
Ok(address)
355+
match crate::cgroup::set_cgroup_and_oom_score(_child.id()) {
356+
Ok(_) => Ok(address),
357+
Err(error) => {
358+
remove_socket(&address).await?;
359+
Err(error)
360+
}
361+
}
352362
}
353363

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

0 commit comments

Comments
 (0)