Skip to content

Commit ce7e5c0

Browse files
committed
fix: ensure network cleanup runs when VMM is already dead
Signed-off-by: goyalpalak18 <goyalpalak1806@gmail.com>
1 parent 66f01ee commit ce7e5c0

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

pkg/unikontainers/hypervisors/utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func killProcess(pid int) error {
7171
const timeout = 2 * time.Second
7272
err := syscall.Kill(pid, unix.SIGKILL)
7373
if err != nil {
74+
if errors.Is(err, syscall.ESRCH) {
75+
// Process already dead, nothing to do
76+
return nil
77+
}
7478
return err
7579
}
7680
deadline := time.Now().Add(timeout)

pkg/unikontainers/unikontainers.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -555,18 +555,23 @@ func (u *Unikontainer) Kill() error {
555555
if err != nil {
556556
return err
557557
}
558-
err = vmm.Stop(u.State.Pid)
559-
if err != nil {
560-
return err
558+
// Attempt to stop VMM process. If it's already dead, vmm.Stop() returns nil.
559+
// We save any error but continue with network cleanup regardless.
560+
stopErr := vmm.Stop(u.State.Pid)
561+
if stopErr != nil {
562+
uniklog.Warnf("vmm.Stop returned error (will continue with cleanup): %v", stopErr)
561563
}
562564

565+
// Always clean up network resources, regardless of VMM state.
566+
// The TAP device and TC rules exist independently of the VMM process.
563567
// TODO: tap0_urunc should not be hardcoded
564-
err = network.Cleanup("tap0_urunc")
565-
if err != nil {
566-
uniklog.Errorf("failed to delete tap0_urunc: %v", err)
568+
cleanupErr := network.Cleanup("tap0_urunc")
569+
if cleanupErr != nil {
570+
uniklog.Errorf("failed to delete tap0_urunc: %v", cleanupErr)
567571
}
568572

569-
return nil
573+
// Return vmm.Stop error if any (network cleanup errors are logged but not fatal)
574+
return stopErr
570575
}
571576

572577
// Delete removes the containers base directory and its contents

0 commit comments

Comments
 (0)