abiosoft/colima · error
invalid pid
Error message
invalid pid: %v
What it means
`colima daemon status` reads the daemon pid file and parses its content with strconv.Atoi, deliberately discarding the parse error. Any content Atoi cannot parse in full (empty file, trailing newline, spaces, non-numeric text) yields pid 0 and this error fires, echoing the raw file bytes in the message. It means the pid file exists but is corrupt or malformed, not that the daemon misbehaved.
Solutions
- Remove the stale pid file (the daemon is not running anyway): delete dir()/daemon.pid reported by daemon info, then run `colima daemon start`
- If it recurs, stop the daemon cleanly with `colima daemon stop` instead of killing the process by hand
- Patch daemon.go:123-126 to use strconv.Atoi(strings.TrimSpace(string(p))) and surface the parse error instead of ignoring it
Example fix
// before
pid, _ := strconv.Atoi(string(p))
if pid == 0 {
return fmt.Errorf("invalid pid: %v", string(p))
}
// after
pid, err := strconv.Atoi(strings.TrimSpace(string(p)))
if err != nil || pid <= 0 {
return fmt.Errorf("invalid pid %q in %s: %w", string(p), info.PidFile, err)
} Defensive patterns
Strategy: validation
Validate before calling
// Go: verify the pid file parses BEFORE calling daemon status
func pidFileValid(pidFile string) bool {
b, err := os.ReadFile(pidFile)
if err != nil {
return false
}
pid, err := strconv.Atoi(strings.TrimSpace(string(b)))
return err == nil && pid > 0
}
if !pidFileValid(daemon.Info().PidFile) {
_ = os.Remove(daemon.Info().PidFile) // stale; start fresh
} Prevention
- Always stop the daemon with `colima daemon stop`; never kill it with kill -9, which can leave a truncated pid file
- Do not hand-edit or truncate daemon.pid
- If you maintain this code: use strconv.Atoi(strings.TrimSpace(string(p))) and propagate the parse error instead of discarding it
When it happens
Trigger: Calling daemon status/start-stop plumbing when info.PidFile exists but is empty (daemon crashed mid-write), contains '123\n' (strconv.Atoi rejects the trailing newline), has whitespace, or was written by a different colima version/profile with a different format.
Common situations: Unclean daemon shutdown (kill -9, host crash) truncating the pid file; running mixed colima versions (brew vs. nightly) sharing the daemon directory; manually editing or `echo $$ >`-ing the pid file; empty file left behind by a failed daemon start.
Related errors
- pid file not found
- process signal(0) returned error
- cannot make dir
- error checking vmnet process
- process not found
AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15).
Data as JSON: /api/errors/fa2d94489faff6c8.
Report an issue: GitHub.
Appendix: source
Thrown at cmd/daemon/daemon.go:125
}
}
}
func status() error {
info := Info()
if _, err := os.Stat(info.PidFile); err != nil {
return fmt.Errorf("pid file not found: %w", err)
}
// check if process is actually running
p, err := os.ReadFile(info.PidFile)
if err != nil {
return fmt.Errorf("error reading pid file: %w", err)
}
pid, _ := strconv.Atoi(string(p))
if pid == 0 {
return fmt.Errorf("invalid pid: %v", string(p))
}
process, err := os.FindProcess(pid)
if err != nil {
return fmt.Errorf("process not found: %v", err)
}
if err := process.Signal(syscall.Signal(0)); err != nil {
return fmt.Errorf("process signal(0) returned error: %w", err)
}
return nil
}
const (
pidFileName = "daemon.pid"
logFileName = "daemon.log"
)View on GitHub (pinned to c3a5f9184d)