limactl start fails with stale ha.sock/ha.pid from unclean shutdown
- Dominant language
- Go
- Stars
- 21.9k
- Forks
- 957
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 53
Description
If the system shuts down before `limactl start --foreground` finishes cleanup (signal handler in `hostagent.go`), stale `ha.pid` and `ha.sock` files remain in the instance directory. On the next boot, `limactl start` tries to connect to the stale `ha.sock`, gets connection refused, and exits with a fatal error instead of cleaning up and starting fresh.
The hostagent command already has `defer os.RemoveAll(pidfile)` and signal handling via `signalCh`, but macOS may kill the process before cleanup completes during a fast shutdown. `limactl start` could check whether the PID in `ha.pid` is actually running before attempting to connect to `ha.sock`, and clean up stale files if it's not.
This is one of several issues that make Lima unusable for unattended auto-start via LaunchDaemon. See also #2252.
**Environment:** macOS 15.7.7, Lima 2.1.x (fork), LaunchDaemon with `RunAtLoad`.
Contributor guide
Research direction
Start at the limactl start path and the signal handling in hostagent.go. Trace how ha.pid and ha.sock are checked before connecting, and inspect the existing cleanup behavior. Done means a stale PID/socket from an unclean shutdown is removed and the instance starts normally; verify with the relevant Lima start and hostagent tests if available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 70/100