{"record":{"id":"9c103b3031508fb6","repo":"lima-vm/lima","slug":"failed-to-get-hostname-for-instance-q-err-w","errorCode":null,"errorMessage":"failed to get hostname for instance %#q, err: %w (out=%#q)","messagePattern":"failed to get hostname for instance %#q, err: %w \\(out=%#q\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/driver/wsl2/vm_windows.go","lineNumber":290,"sourceCode":"\t\treturn strings.TrimSpace(string(out)), nil\n\t}\n\t// Alpine\n\tcmd = exec.CommandContext(ctx, \"wsl.exe\", \"-d\", distroName, \"sh\", \"-c\", `ip route get 1 | awk '{gsub(\"^.*src \",\"\"); print $1; exit}'`)\n\tout, err = cmd.CombinedOutput()\n\tif err == nil {\n\t\treturn strings.TrimSpace(string(out)), nil\n\t}\n\t// fallback\n\tcmd = exec.CommandContext(ctx, \"wsl.exe\", \"-d\", distroName, \"hostname\", \"-i\")\n\tout, err = cmd.CombinedOutput()\n\tif err == nil {\n\t\tip := net.ParseIP(strings.TrimSpace(string(out)))\n\t\t// some distributions use \"127.0.1.1\" as the host IP, but we want something that we can route to here\n\t\tif ip != nil && !ip.IsLoopback() {\n\t\t\treturn strings.TrimSpace(string(out)), nil\n\t\t}\n\t}\n\treturn \"\", fmt.Errorf(\"failed to get hostname for instance %#q, err: %w (out=%#q)\", instName, err, string(out))\n}\n","sourceCodeStart":272,"sourceCodeEnd":292,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/driver/wsl2/vm_windows.go#L272-L292","documentation":"getSSHAddress resolves the instance IP by asking the distro for its hostname resolution (e.g. via `hostname -I`-style wsl command). If the command fails, or yields nothing routable (empty or loopback like 127.0.1.1), Lima cannot produce a reachable SSH address.","triggerScenarios":"InspectStatus calls getSSHAddress; the wsl command used to fetch the guest IP exits non-zero (distro stopped/broken) or returns only loopback addresses such as 127.0.1.1 used by some Debian-based distros.","commonSituations":"Instance not fully booted so the guest networking isn't up; distro stopped, so wsl commands return errors; /etc/hosts in the distro maps hostname only to 127.0.1.1; unusual distro without standard hostname tooling.","solutions":["Ensure the instance is running (`limactl start <instance>`) before querying its SSH address","Check the out= portion; if empty, boot the distro manually (`wsl -d lima-<instance>`) and inspect /etc/hosts and `hostname -I`","If only 127.0.1.1 is returned, verify guest networking: `wsl -d lima-<instance> ip addr`, restart WSL networking (`wsl --shutdown` then start)","Update WSL (`wsl --update`) — newer versions provide proper localhost/NAT addressing"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Only query SSH address when instance is running\nconst state = await limactlInspect(inst);\nif (state.status !== 'Running') throw new Error('Start the instance first');","typeGuard":"function isSSHAddrError(e) { return /failed to get hostname/.test(String(e)); }","tryCatchPattern":"async function sshAddressWithRetry(inst, attempts = 5) {\n  for (let i = 0; i < attempts; i++) {\n    try { return await limactlShell(inst, 'hostname -I'); }\n    catch (e) {\n      if (!/failed to get hostname/.test(String(e)) || i === attempts - 1) throw e;\n      await new Promise(r => setTimeout(r, 2000)); // wait for guest networking\n    }\n  }\n}","preventionTips":["Wait for full guest boot before resolving the SSH address","Check guest /etc/hosts doesn't map hostname solely to 127.0.1.1","If only loopback IPs are returned, `wsl --shutdown` and restart to reset NAT networking","Keep WSL updated for reliable localhost forwarding"],"tags":["wsl2","ssh-address","networking"],"backgroundTag":"ssh-address-resolution-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}