From 5cafe217703b44edfa5de964a1ec1af73ee2dd41 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Mon, 12 Sep 2022 21:56:15 -0700 Subject: [PATCH] runtime: make StopVM thread-safe StopVM can be invoked by multiple threads and needs to be thread-safe Fixes: #5155 Signed-off-by: Feng Wang --- src/runtime/virtcontainers/qemu.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index 439cd47f72..051d405ffc 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -110,6 +110,8 @@ type qemu struct { nvdimmCount int stopped bool + + mu sync.Mutex } const ( @@ -968,6 +970,8 @@ func (q *qemu) waitVM(ctx context.Context, timeout int) error { // StopVM will stop the Sandbox's VM. func (q *qemu) StopVM(ctx context.Context, waitOnly bool) error { + q.mu.Lock() + defer q.mu.Unlock() span, _ := katatrace.Trace(ctx, q.Logger(), "StopVM", qemuTracingTags, map[string]string{"sandbox_id": q.id}) defer span.End()