From 0e47cfc4c779273384f7737de6f744b2bbf75a47 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. Signed-off-by: Beraldo Leal --- 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 3a8c55cd38..d856490e5b 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -1122,22 +1122,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 } }