Skip to content

Commit 7421fd6

Browse files
committed
Wait for non-child hypervisor exit before finishing kill
After a hypeman restart the hypervisor is not our child, so Wait4 returns ECHILD immediately and the kill loop finished before the process had exited. Poll for actual process exit in that case.
1 parent 9ea50ef commit 7421fd6

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

lib/instances/delete.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,16 @@ func (m *manager) killHypervisor(ctx context.Context, inst *Instance) error {
220220
for i := 0; i < 50; i++ { // 50 * 100ms = 5 seconds
221221
var wstatus syscall.WaitStatus
222222
wpid, err := syscall.Wait4(pid, &wstatus, syscall.WNOHANG, nil)
223-
if err != nil || wpid == pid {
224-
// Process reaped successfully or error (likely ECHILD if already reaped)
223+
if err == nil && wpid == pid {
225224
log.DebugContext(ctx, "hypervisor process killed and reaped", "instance_id", inst.Id, "pid", pid)
226225
break
227226
}
227+
if err != nil {
228+
if killErr := syscall.Kill(pid, 0); killErr == syscall.ESRCH {
229+
log.DebugContext(ctx, "hypervisor process killed", "instance_id", inst.Id, "pid", pid)
230+
break
231+
}
232+
}
228233
if i == 49 {
229234
log.WarnContext(ctx, "hypervisor process did not exit in time", "instance_id", inst.Id, "pid", pid)
230235
}

0 commit comments

Comments
 (0)