Skip to content

fix(darwin): pin main goroutine to OS thread 0 for VZ GUI#5036

Open
trodemaster wants to merge 1 commit into
lima-vm:masterfrom
trodemaster:fix/darwin-lock-main-thread
Open

fix(darwin): pin main goroutine to OS thread 0 for VZ GUI#5036
trodemaster wants to merge 1 commit into
lima-vm:masterfrom
trodemaster:fix/darwin-lock-main-thread

Conversation

@trodemaster
Copy link
Copy Markdown

VZVirtualMachineView requires GUI operations to run on the process main
thread. limactl already calls runtime.LockOSThread() in hostagentAction,
but that runs too late: by the time cobra dispatches the hostagent
subcommand, Go's scheduler has already migrated the main goroutine to a
worker thread. On macOS 26 this causes a SIGTRAP when the VZ driver calls
startVirtualMachineWindow.

Adding runtime.LockOSThread() to an init() function ensures the main
goroutine is pinned to thread 0 before main() runs. The build tag
restricts the file to darwin; Linux and Windows are unaffected.

Tested on macOS 26.5 (25F71), Apple Silicon, with Lima 2.1.2-beta.0:
fresh macOS 26 guest install from IPSW and start of an existing macOS 26
VM with video.display: default both complete without SIGTRAP.

Assisted-by: Commercial LLM tooling

Fixes #4743

VZVirtualMachineView requires GUI operations on the process main thread.
The existing runtime.LockOSThread() in hostagentAction runs too late —
Go's scheduler can migrate the main goroutine to a worker thread before
cobra dispatches, causing SIGTRAP on macOS 26 when the VZ driver calls
startVirtualMachineWindow.

Add an init() that calls runtime.LockOSThread() before main() runs,
ensuring the goroutine stays on thread 0 from process start.

Fixes: lima-vm#4743
@trodemaster trodemaster deleted the fix/darwin-lock-main-thread branch May 25, 2026 20:15
@trodemaster trodemaster restored the fix/darwin-lock-main-thread branch May 25, 2026 20:17
@trodemaster trodemaster reopened this May 25, 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.

macOS guest: signal arrived during cgo execution (vz/v3._Cfunc_startVirtualMachineWindow)

1 participant