From 075a311282ad37464109e9b2d41fbe2e19b7432f Mon Sep 17 00:00:00 2001 From: Beraldo Leal Date: Wed, 24 May 2023 11:27:04 -0400 Subject: [PATCH] runtime: sending SIGKILL to qemu 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 #6757. Backport of #6959. Signed-off-by: Beraldo Leal (cherry picked from commit 0e47cfc4c779273384f7737de6f744b2bbf75a47) --- src/runtime/virtcontainers/qemu.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index 0d4fa3e85b..400178f4df 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -1108,22 +1108,21 @@ func (q *qemu) StopVM(ctx context.Context, waitOnly bool) (err error) { return err } + pids := q.GetPids() + if len(pids) == 0 { + return errors.New("cannot determine QEMU PID") + } + pid := pids[0] + if waitOnly { - pids := q.GetPids() - if len(pids) == 0 { - return errors.New("cannot determine QEMU PID") - } - - pid := pids[0] - 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 } }