From ce7e5c06a16c48eed0b17d6a6f7a3b08ec05df7a Mon Sep 17 00:00:00 2001 From: goyalpalak18 Date: Sun, 25 Jan 2026 21:40:04 +0530 Subject: [PATCH] fix: ensure network cleanup runs when VMM is already dead Signed-off-by: goyalpalak18 --- pkg/unikontainers/hypervisors/utils.go | 4 ++++ pkg/unikontainers/unikontainers.go | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pkg/unikontainers/hypervisors/utils.go b/pkg/unikontainers/hypervisors/utils.go index 6694c6eb..c3de7c8b 100644 --- a/pkg/unikontainers/hypervisors/utils.go +++ b/pkg/unikontainers/hypervisors/utils.go @@ -71,6 +71,10 @@ func killProcess(pid int) error { const timeout = 2 * time.Second err := syscall.Kill(pid, unix.SIGKILL) if err != nil { + if errors.Is(err, syscall.ESRCH) { + // Process already dead, nothing to do + return nil + } return err } deadline := time.Now().Add(timeout) diff --git a/pkg/unikontainers/unikontainers.go b/pkg/unikontainers/unikontainers.go index 85dc1e2a..d501aad7 100644 --- a/pkg/unikontainers/unikontainers.go +++ b/pkg/unikontainers/unikontainers.go @@ -555,18 +555,23 @@ func (u *Unikontainer) Kill() error { if err != nil { return err } - err = vmm.Stop(u.State.Pid) - if err != nil { - return err + // Attempt to stop VMM process. If it's already dead, vmm.Stop() returns nil. + // We save any error but continue with network cleanup regardless. + stopErr := vmm.Stop(u.State.Pid) + if stopErr != nil { + uniklog.Warnf("vmm.Stop returned error (will continue with cleanup): %v", stopErr) } + // Always clean up network resources, regardless of VMM state. + // The TAP device and TC rules exist independently of the VMM process. // TODO: tap0_urunc should not be hardcoded - err = network.Cleanup("tap0_urunc") - if err != nil { - uniklog.Errorf("failed to delete tap0_urunc: %v", err) + cleanupErr := network.Cleanup("tap0_urunc") + if cleanupErr != nil { + uniklog.Errorf("failed to delete tap0_urunc: %v", cleanupErr) } - return nil + // Return vmm.Stop error if any (network cleanup errors are logged but not fatal) + return stopErr } // Delete removes the containers base directory and its contents