Skip to content

wsl2: stop spinning in for { <-ctx.Done() } after instance stop#4892

Open
mn-ram wants to merge 1 commit intolima-vm:masterfrom
mn-ram:fix/wsl2-bootscript-spin-loop
Open

wsl2: stop spinning in for { <-ctx.Done() } after instance stop#4892
mn-ram wants to merge 1 commit intolima-vm:masterfrom
mn-ram:fix/wsl2-bootscript-spin-loop

Conversation

@mn-ram
Copy link
Copy Markdown
Contributor

@mn-ram mn-ram commented Apr 27, 2026

Fixes #4891.

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 every iteration, so the goroutine hot-loops calling getWslStatus and stopVM forever — pinning a CPU core and flooding wslservice.exe with wsl.exe subprocesses.

Drop the for {/} wrapper so the goroutine waits once and exits.

Test plan

  • GOOS=windows go build ./pkg/driver/wsl2/...
  • GOOS=windows go vet ./pkg/driver/wsl2/...

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>
@mn-ram
Copy link
Copy Markdown
Contributor Author

mn-ram commented Apr 27, 2026

The Windows tests (WSL2) failure looks like a runner issue, not caused by this PR.

Logs:

  • create/start/stop all passed
  • Failure on immediate restart → HCS_E_CONNECTION_TIMEOUT
  • wsl.exe --unregister hung → job timed out

This error is from Windows (Hyper-V), not the Go code touched here.

That said, earlier loop spam (getWslStatuswsl.exe) might have affected timing on restart, so can’t fully rule it out.

Likely a flake — could you please re-run to confirm?

@unsuman unsuman added this to the v2.2.0 milestone Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wsl2: provisionVM goroutine hot-loops on for { <-ctx.Done() } after instance stop

2 participants