From 89cb69d2f22724eb38e3a78e8b24139b44aa9207 Mon Sep 17 00:00:00 2001 From: mn-ram <235066282+mn-ram@users.noreply.github.com> Date: Mon, 27 Apr 2026 07:05:31 +0530 Subject: [PATCH] wsl2: stop spinning in for { <-ctx.Done() } after instance stop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The boot-script goroutine in provisionVM wraps a single context-cancellation wait in `for {}`. Once ctx is canceled (every limactl stop / shutdown), <-ctx.Done() returns immediately on each iteration, and the goroutine hot-loops calling getWslStatus and stopVM forever — pinning a CPU core and flooding wslservice.exe with wsl.exe subprocess invocations. The intent was clearly to wait once and stop the VM, so drop the for loop. Signed-off-by: mn-ram <235066282+mn-ram@users.noreply.github.com> --- pkg/driver/wsl2/vm_windows.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/driver/wsl2/vm_windows.go b/pkg/driver/wsl2/vm_windows.go index 7069df96ed7..ac83cf4553f 100644 --- a/pkg/driver/wsl2/vm_windows.go +++ b/pkg/driver/wsl2/vm_windows.go @@ -132,13 +132,11 @@ func provisionVM(ctx context.Context, instanceDir, instanceName, distroName stri "check /var/log/lima-init.log for more details (out=%q)", cmd.Args, err, string(out)) } - for { - <-ctx.Done() - logrus.Info("Context closed, stopping vm") - if status, err := getWslStatus(ctx, instanceName); err == nil && - status == limatype.StatusRunning { - _ = stopVM(ctx, distroName) - } + <-ctx.Done() + logrus.Info("Context closed, stopping vm") + if status, err := getWslStatus(ctx, instanceName); err == nil && + status == limatype.StatusRunning { + _ = stopVM(ctx, distroName) } }()