Skip to content

Commit

Permalink
runtime: sending SIGKILL to qemu
Browse files Browse the repository at this point in the history
There is a race condition when virtiofsd is killed without finishing all
the clients. Because of that, when a pod is stopped, QEMU detects
virtiofsd is gone, which is legitimate.

Sending a SIGTERM first before killing could introduce some latency
during the shutdown.

Fixes kata-containers#6757.
Backport of kata-containers#6959.

Signed-off-by: Beraldo Leal <bleal@redhat.com>
  • Loading branch information
beraldoleal committed May 25, 2023
1 parent 68e7e00 commit 2f43a9d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/runtime/virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,22 +1108,21 @@ func (q *qemu) StopVM(ctx context.Context, waitOnly bool) (err error) {
return err
}

if waitOnly {
pids := q.GetPids()
if len(pids) == 0 {
return errors.New("cannot determine QEMU PID")
}

pid := pids[0]
pids := q.GetPids()
if len(pids) == 0 {
return errors.New("cannot determine QEMU PID")
}
pid := pids[0]

if waitOnly {
err := utils.WaitLocalProcess(pid, qemuStopSandboxTimeoutSecs, syscall.Signal(0), q.Logger())
if err != nil {
return err
}
} else {
err := q.qmpMonitorCh.qmp.ExecuteQuit(q.qmpMonitorCh.ctx)
err = syscall.Kill(pid, syscall.SIGKILL)
if err != nil {
q.Logger().WithError(err).Error("Fail to execute qmp QUIT")
q.Logger().WithError(err).Error("Fail to send SIGKILL to qemu")
return err
}
}
Expand Down

0 comments on commit 2f43a9d

Please sign in to comment.