File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
crates/sandchest-node/src Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments