{"record":{"id":"2ed905387c0e1795","repo":"lima-vm/lima","slug":"failed-to-write-driver-pid-file-w","errorCode":null,"errorMessage":"failed to write driver PID file: %w","messagePattern":"failed to write driver PID file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/driver/external/server/server.go","lineNumber":227,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open external driver log file: %w\", err)\n\t}\n\tdefer func() {\n\t\t_ = logFile.Close()\n\t}()\n\n\tcmd := exec.CommandContext(ctx, extDriver.Path, \"--inst-dir\", instanceDir)\n\tcmd.Stderr = logFile\n\tif err := cmd.Start(); err != nil {\n\t\treturn fmt.Errorf(\"failed to start external driver: %w\", err)\n\t}\n\n\tpid := cmd.Process.Pid\n\tpidFilePath := driverPIDFilePath(instanceDir, extDriver.Name)\n\tif err := os.WriteFile(pidFilePath, []byte(strconv.Itoa(pid)), 0o644); err != nil {\n\t\t_ = cmd.Process.Kill()\n\t\t_, _ = cmd.Process.Wait()\n\t\treturn fmt.Errorf(\"failed to write driver PID file: %w\", err)\n\t}\n\n\tdriverLogger := extDriver.Logger.WithField(\"driver\", extDriver.Name)\n\n\tprocExit := make(chan error, 1)\n\tgo func() {\n\t\tprocExit <- cmd.Wait()\n\t\tclose(procExit)\n\t\t_ = os.Remove(pidFilePath)\n\t}()\n\n\t// Wait for the socket file to be created by the external driver.\n\tsocketWaitCtx, socketWaitCancel := context.WithTimeout(ctx, 10*time.Second)\n\tdefer socketWaitCancel()\n\tticker := time.NewTicker(100 * time.Millisecond)\n\tdefer ticker.Stop()\n\tfor {\n\t\tselect {","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/driver/external/server/server.go#L209-L245","documentation":"During external driver startup, lima writes the spawned driver process PID to a PID file in the instance directory so Stop can later find and signal the process. This error wraps the os.WriteFile failure: the process was already spawned, so it is killed and reaped before returning. It indicates a filesystem-level problem, not a driver problem.","triggerScenarios":"CreateConfiguredDriver -> Start spawns the external driver binary successfully, then os.WriteFile(pidFilePath, ...) fails — e.g. instanceDir missing or deleted, disk full, read-only mount, or permission denied on the instance directory.","commonSituations":"LIMA_HOME on a read-only or full volume; instance directory removed by another process while starting; restrictive umask/permissions after copying instance dirs between users; macOS/Windows sync tools locking the directory.","solutions":["Check the instance directory exists and is writable (ls -ld ~/.lima/<instance>; create it if missing)","Free disk space on the volume holding LIMA_HOME","Fix permissions/ownership of the instance directory (chown/chmod)","If the directory was moved or LIMA_HOME changed, re-create the instance"],"exampleFix":"// before: starting with a non-existent instance dir\nos.MkdirAll(instanceDir, 0o755) // missing -> os.WriteFile fails\n// after: ensure the directory exists before Start\nif err := os.MkdirAll(instanceDir, 0o755); err != nil {\n\treturn fmt.Errorf(\"failed to prepare instance dir: %w\", err)\n}","handlingStrategy":"validation","validationCode":"info, err := os.Stat(instanceDir)\nif err != nil || !info.IsDir() {\n\treturn fmt.Errorf(\"instance dir %s missing or not a directory\", instanceDir)\n}\nif err := os.MkdirAll(instanceDir, 0o755); err != nil {\n\treturn err\n}","typeGuard":null,"tryCatchPattern":"if err := limactl.Start(inst); err != nil {\n\tvar fsErr *os.PathError\n\tif errors.As(err, &fsErr) {\n\t\t// disk/permission issue on instance dir: repair and retry once\n\t}\n\treturn err\n}","preventionTips":["Keep LIMA_HOME on a local, writable volume with free space","Don't move/delete instance directories while VMs are starting","Watch for 'No space left on device' disk-full alerts","Use consistent LIMA_HOME across tools to avoid split instance dirs"],"tags":["filesystem","external-driver","pid-file","startup"],"backgroundTag":"pid-file-write-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}