{"record":{"id":"4c885e719fc594fc","repo":"lima-vm/lima","slug":"failed-to-determine-if-another-hostagent-is-runnin","errorCode":null,"errorMessage":"failed to determine if another hostagent is running: %w","messagePattern":"failed to determine if another hostagent is running: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/hostagent.go","lineNumber":52,"sourceCode":"\thostagentCommand.Flags().String(\"socket\", \"\", \"Path of hostagent socket\")\n\thostagentCommand.Flags().Bool(\"run-gui\", false, \"Run GUI synchronously within hostagent\")\n\thostagentCommand.Flags().String(\"guestagent\", \"\", \"Local file path (not URL) of lima-guestagent.OS-ARCH[.gz]\")\n\thostagentCommand.Flags().String(\"nerdctl-archive\", \"\", \"Local file path (not URL) of nerdctl-full-VERSION-GOOS-GOARCH.tar.gz\")\n\thostagentCommand.Flags().Bool(\"progress\", false, \"Show provision script progress by monitoring cloud-init logs\")\n\treturn hostagentCommand\n}\n\nfunc hostagentAction(cmd *cobra.Command, args []string) error {\n\tctx := cmd.Context()\n\tpidfile, err := cmd.Flags().GetString(\"pidfile\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tif pidfile != \"\" {\n\t\tif existingPID, err := store.ReadPIDFile(pidfile); existingPID != 0 {\n\t\t\treturn fmt.Errorf(\"another hostagent may already be running with pid %d (pidfile %#q)\", existingPID, pidfile)\n\t\t} else if err != nil {\n\t\t\treturn fmt.Errorf(\"failed to determine if another hostagent is running: %w\", err)\n\t\t}\n\t\tif err := store.WritePIDFile(pidfile, os.Getpid()); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tdefer os.RemoveAll(pidfile)\n\t}\n\tsocket, err := cmd.Flags().GetString(\"socket\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tif socket == \"\" {\n\t\treturn errors.New(\"socket must be specified (limactl version mismatch?)\")\n\t}\n\n\tinstName := args[0]\n\n\trunGUI, err := cmd.Flags().GetBool(\"run-gui\")\n\tif err != nil {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/hostagent.go#L34-L70","documentation":"Before writing its own PID, the hostagent calls store.ReadPIDFile to check for an existing runner; if that read fails for any reason (unreadable file, permission error, malformed contents) the command cannot know whether another hostagent is running and fails closed with this wrapped error.","triggerScenarios":"Calling hostagent with --pidfile where store.ReadPIDFile returns an error and a zero PID — e.g. pidfile exists but is not readable, is a directory, or contains garbage that cannot be parsed as a PID.","commonSituations":"LIMA_HOME on a mounted volume with wrong permissions; a corrupted pidfile after a crash or disk-full event; pidfile path pointing at a directory instead of a file.","solutions":["Inspect the pidfile: `ls -la <pidfile>` and `cat <pidfile>`; fix permissions or delete the corrupted file","Ensure the LIMA_HOME instance directory is writable by the current user","Retry the start after removing the malformed pidfile"],"exampleFix":"// before\n# pidfile unreadable (root-owned after sudo run)\n// after\nsudo chown -R $(whoami) ~/.lima/myinstance && limactl start myinstance","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(pidfile); err == nil && !fi.Mode().IsRegular() {\n    return fmt.Errorf(\"pidfile %s is not a regular file\", pidfile)\n}","typeGuard":"func pidfileReadable(pidfile string) bool {\n    f, err := os.Open(pidfile)\n    if err != nil { return false }\n    f.Close()\n    return true\n}","tryCatchPattern":"if err := startHostagent(); err != nil {\n    var wrapped string = err.Error()\n    if strings.Contains(wrapped, \"failed to determine if another hostagent\") {\n        os.Remove(pidfile) // clear corrupted pidfile, then retry\n    }\n    return err\n}","preventionTips":["Keep LIMA_HOME on a local filesystem with correct permissions","Avoid running limactl as different users against the same instance","Recreate corrupted pidfiles after crashes"],"tags":["cli","process","pidfile","filesystem","lima"],"backgroundTag":"pidfile-unreadable","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}