{"record":{"id":"79dd84efed2157c2","repo":"lima-vm/lima","slug":"failed-to-read-pid-file-q-w","errorCode":null,"errorMessage":"failed to read PID file %#q: %w","messagePattern":"failed to read PID file %#q: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/networks/reconcile/reconcile.go","lineNumber":380,"sourceCode":"\t\t\t}\n\t\t\treturn &daemonExitedError{err: waitErr}\n\t\tcase <-timer.C:\n\t\t\t_ = cmd.Process.Kill()\n\t\t\t<-waitCh\n\t\t\treturn &daemonStuckError{timeout: timeout}\n\t\tcase <-ticker.C:\n\t\t\t// re-check the PID file on the next loop iteration\n\t\t}\n\t}\n}\n\n// pidFileWritten reports whether the daemon has written a valid PID file. A read\n// error (e.g. a corrupt or unreadable PID file) is non-transient and is returned so\n// the caller can fail fast rather than mistake it for a daemon that is slow to start.\nfunc pidFileWritten(pidFile string) (bool, error) {\n\tpid, err := store.ReadPIDFile(pidFile)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to read PID file %#q: %w\", pidFile, err)\n\t}\n\treturn pid != 0, nil\n}\n\n// stderrHint returns the daemon's stderr (or a pointer to the log) to append to errors.\nfunc stderrHint(stderrLog string) string {\n\tif b, err := os.ReadFile(stderrLog); err == nil && len(b) > 0 {\n\t\treturn fmt.Sprintf(\" (stderr: %s)\", strings.TrimSpace(string(b)))\n\t}\n\treturn fmt.Sprintf(\" (check %#q)\", stderrLog)\n}\n\nfunc stopNetwork(ctx context.Context, cfg *networks.Config, name string) error {\n\tlogrus.Debugf(\"Make sure %#q network is stopped\", name)\n\t// Handle usernet first without sudo requirements\n\tisUsernet, err := cfg.Usernet(name)\n\tif err != nil {\n\t\treturn err","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/networks/reconcile/reconcile.go#L362-L398","documentation":"Lima could not read the network daemon's PID file while polling for daemon readiness. Unlike 'file not yet created' (which just means not-ready), a read error such as a corrupt or unreadable PID file is treated as non-transient and aborts startup immediately so it is not mistaken for a slow daemon.","triggerScenarios":"pidFileWritten calls store.ReadPIDFile(pidFile) during waitForDaemon polling and gets an error other than not-exists-yet — e.g. a malformed/corrupt PID file, permission denied on the file, or a PID file containing invalid content.","commonSituations":"A previous crashed run left a truncated or garbage PID file under ~/.lima/networks, the file was edited by hand, or permission changes on ~/.lima make the file unreadable.","solutions":["Delete the corrupt PID file shown in the message and retry limactl start","Ensure no other Lima instance/process is concurrently writing the same PID file","Check permissions on the file and its parent directory (~/.lima/networks)","Set a distinct LIMA_HOME if multiple Lima versions share the same instance dir"],"exampleFix":"// before: corrupt PID file\nrm ~/.lima/networks/lima-shared_pid\n// after: clean state, retry\nlimactl start","handlingStrategy":"validation","validationCode":"func validPIDFile(path string) bool {\n    b, err := os.ReadFile(path)\n    if err != nil { return true } // missing is fine (not ready yet)\n    var pid int\n    _, err = fmt.Sscanf(strings.TrimSpace(string(b)), \"%d\", &pid)\n    return err == nil && pid > 0\n}","typeGuard":null,"tryCatchPattern":"if err := startNetwork(); err != nil {\n    if strings.Contains(err.Error(), \"failed to read PID file\") {\n        os.Remove(pidFilePath) // clear corrupt file, retry\n    }\n}","preventionTips":["Never hand-edit PID files under ~/.lima/networks","Remove PID files after force-killing daemons","Avoid concurrent limactl processes sharing one LIMA_HOME","Keep ~/.lima ownership consistent (same user)"],"tags":["network","pid-file","corrupt-file","daemon-startup"],"backgroundTag":"corrupt-pid-file","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}