{"record":{"id":"0e3af1cbdb55bbfa","repo":"abiosoft/colima","slug":"error-reading-pid-file-w","errorCode":null,"errorMessage":"error reading pid file: %w","messagePattern":"error reading pid file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cmd/daemon/daemon.go","lineNumber":121,"sourceCode":"\t\tcase <-ctx.Done():\n\t\t\treturn ctx.Err()\n\t\tdefault:\n\t\t\ttime.Sleep(time.Second * 1)\n\t\t}\n\t}\n\n}\n\nfunc status() error {\n\tinfo := Info()\n\tif _, err := os.Stat(info.PidFile); err != nil {\n\t\treturn fmt.Errorf(\"pid file not found: %w\", err)\n\t}\n\n\t// check if process is actually running\n\tp, err := os.ReadFile(info.PidFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error reading pid file: %w\", err)\n\t}\n\tpid, _ := strconv.Atoi(string(p))\n\tif pid == 0 {\n\t\treturn fmt.Errorf(\"invalid pid: %v\", string(p))\n\t}\n\n\tprocess, err := os.FindProcess(pid)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"process not found: %v\", err)\n\t}\n\n\tif err := process.Signal(syscall.Signal(0)); err != nil {\n\t\treturn fmt.Errorf(\"process signal(0) returned error: %w\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/cmd/daemon/daemon.go#L103-L139","documentation":"Returned by status (cmd/daemon/daemon.go:121) when the pid file exists (os.Stat succeeded) but os.ReadFile on it fails. The %w carries the read error.","triggerScenarios":"Permission denied reading the pid file (created by a root-run daemon, restrictive mode/ACL), or a race where the file is removed between stat and read (concurrent daemon stop/restart).","commonSituations":"Daemon previously started with sudo leaving a root-owned daemon.pid; two colima invocations racing to stop/restart the daemon.","solutions":["Fix ownership of the daemon directory and pid file: `sudo chown -R $(id -un) <daemon-dir>`","If a race is likely, simply retry the status/stop command","If no daemon is actually running (`ps aux | grep -i colima | grep daemon`), delete the unreadable pid file so status cleanly reports not-running"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Probe pid file readability before daemon flows\nif p, err := os.ReadFile(info.PidFile); err != nil {\n    return fmt.Errorf(\"pid file unreadable; fix ownership of the daemon dir or remove the stale pid file\")\n} else if pid, _ := strconv.Atoi(string(p)); pid == 0 {\n    return fmt.Errorf(\"stale pid file\")\n}","typeGuard":null,"tryCatchPattern":"if err := daemonStatus(); err != nil {\n    if strings.Contains(err.Error(), \"error reading pid file\") {\n        // permission or race: chown the daemon dir, or simply retry once\n    }\n    return err\n}","preventionTips":["Never start the daemon via sudo — pid/log files become root-owned","Avoid concurrent daemon stop/restart invocations","If a daemon is genuinely absent, delete the stale pid file so status is clean"],"tags":["daemon","filesystem","permissions","race","colima"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}