Skip to content

Commit a925c04

Browse files
committed
Add pkill fallback to kill orphaned Firecracker
1 parent d6053f0 commit a925c04

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

crates/sandchest-node/src/firecracker.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,29 @@ impl FirecrackerVm {
239239
let _ = self.child.kill().await;
240240
}
241241

242+
// Fallback: kill any orphaned Firecracker process matching this sandbox ID.
243+
// When the jailer uses --new-pid-ns, the Firecracker child may end up in a
244+
// different process group (due to setsid inside the jailer), so the process-
245+
// group kill above only terminates the jailer — Firecracker survives as an
246+
// orphan. This pkill catches it by matching the --id flag.
247+
#[cfg(unix)]
248+
{
249+
let pattern = format!("firecracker.*--id {}", self.sandbox_id);
250+
match tokio::process::Command::new("pkill")
251+
.args(["-9", "-f", &pattern])
252+
.output()
253+
.await
254+
{
255+
Ok(output) if output.status.success() => {
256+
warn!(
257+
sandbox_id = %self.sandbox_id,
258+
"killed orphaned Firecracker process via pkill fallback"
259+
);
260+
}
261+
_ => {} // No match or pkill failed — process already dead, which is fine
262+
}
263+
}
264+
242265
// Clean up sandbox data directory
243266
if Path::new(&self.data_dir).exists() {
244267
if let Err(e) = tokio::fs::remove_dir_all(&self.data_dir).await {

0 commit comments

Comments
 (0)