{"record":{"id":"4f647ce0182977f2","repo":"lima-vm/lima","slug":"failed-to-connect-to-q-w","errorCode":null,"errorMessage":"failed to connect to %#q: %w","messagePattern":"failed to connect to %#q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/instance.go","lineNumber":76,"sourceCode":"\t}\n\tinst.Config = y\n\tinst.Arch = *y.Arch\n\tinst.VMType = *y.VMType\n\tinst.SSHAddress = \"127.0.0.1\"\n\tinst.SSHLocalPort = *y.SSH.LocalPort // maybe 0\n\tinst.SSHConfigFile = filepath.Join(instDir, filenames.SSHConfig)\n\tinst.HostAgentPID, err = ReadPIDFile(filepath.Join(instDir, filenames.HostAgentPID))\n\tif err != nil {\n\t\tinst.Status = limatype.StatusBroken\n\t\tinst.Errors = append(inst.Errors, err)\n\t}\n\n\tif inst.HostAgentPID != 0 {\n\t\thaSock := filepath.Join(instDir, filenames.HostAgentSock)\n\t\thaClient, err := hostagentclient.NewHostAgentClient(haSock)\n\t\tif err != nil {\n\t\t\tinst.Status = limatype.StatusBroken\n\t\t\tinst.Errors = append(inst.Errors, fmt.Errorf(\"failed to connect to %#q: %w\", haSock, err))\n\t\t} else {\n\t\t\tctx, cancel := context.WithTimeout(ctx, 3*time.Second)\n\t\t\tdefer cancel()\n\t\t\tinfo, err := haClient.Info(ctx)\n\t\t\tif err != nil {\n\t\t\t\tinst.Status = limatype.StatusBroken\n\t\t\t\tinst.Errors = append(inst.Errors, fmt.Errorf(\"failed to get Info from %#q: %w\", haSock, err))\n\t\t\t} else {\n\t\t\t\tinst.SSHLocalPort = info.SSHLocalPort\n\t\t\t\tinst.AutoStartedIdentifier = info.AutoStartedIdentifier\n\t\t\t}\n\t\t}\n\t}\n\tif inst.SSHLocalPort == 0 {\n\t\tsshConfigPath := filepath.Join(instDir, filenames.SSHConfig)\n\t\tif port, err := sshPortFromConfig(sshConfigPath); err == nil {\n\t\t\tinst.SSHLocalPort = port\n\t\t} else if !errors.Is(err, os.ErrNotExist) {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/store/instance.go#L58-L94","documentation":"During instance inspection (pkg/store/instance.go Inspect), Lima tried to create a client to the instance's host agent Unix socket but the connection attempt failed at the socket/client level. The instance is marked StatusBroken and the wrapped OS/gRPC error is appended to inst.Errors. This usually means the host agent socket does not exist or is stale (host agent crashed or was killed).","triggerScenarios":"Inspect() is called on an instance whose HostAgentPID is non-zero (a PID file exists) but the host agent socket at <instDir>/filenames.HostAgentSock cannot be dialed: socket file missing, stale socket after a crash, permission denied on the socket, or socket path deleted.","commonSituations":"VM was killed or the machine rebooted leaving a stale PID file; hostagent process crashed mid-run; ~/.lima directory partially deleted or moved; running limactl inside a container/sandbox without access to the Unix socket; wrong LIMA_HOME pointing at another user's instance dir.","solutions":["Run `limactl stop <instance>` then `limactl start <instance>` to clear the stale PID/socket state","If stop hangs, remove the stale socket and PID files under ~/.lima/<instance> (ha.pid, host agent sock) and restart","Verify LIMA_HOME points to the correct instance directory","Check hostagent logs in ~/.lima/<instance>/ha_stderr.log for the underlying crash cause","Check filesystem permissions on the socket file"],"exampleFix":"// before: inspect shows broken instance with connection error\nlimactl list  # instance shows Broken\n// after\nlimactl stop broken-vm; limactl start broken-vm","handlingStrategy":"validation","validationCode":"// Before relying on an instance, verify the host agent socket exists\nhaSock := filepath.Join(limaHome, instName, \"ha.sock\")\nif _, err := os.Stat(haSock); err != nil {\n    // socket stale/missing: treat instance as stopped/broken, do not call Inspect-dependent logic\n}","typeGuard":null,"tryCatchPattern":"inst, err := store.Inspect(ctx, instDir)\nif err != nil {\n    for _, e := range inst.Errors {\n        var opErr *net.OpError\n        if errors.As(e, &opErr) {\n            // stale socket: stop+start the instance\n        }\n    }\n}","preventionTips":["Shut down instances with `limactl stop`, never by killing processes directly","After a host reboot, run `limactl list` to detect Broken instances early","Keep LIMA_HOME consistent; do not share instance dirs between users"],"tags":["lima","hostagent","unix-socket","broken-instance"],"backgroundTag":"unix-socket-connection-refused","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}