{"record":{"id":"0ebbd303a1c443da","repo":"lima-vm/lima","slug":"failed-to-get-hostname-w","errorCode":null,"errorMessage":"failed to get hostname: %w","messagePattern":"failed to get hostname: %w","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/osutil/machineid.go","lineNumber":32,"sourceCode":"\t\"os/exec\"\n\t\"runtime\"\n\t\"strings\"\n\t\"sync\"\n\n\t\"github.com/sirupsen/logrus\"\n\n\t\"github.com/lima-vm/lima/v2/pkg/plist\"\n)\n\nvar MachineID = sync.OnceValue(func() string {\n\tx, err := machineID(context.Background())\n\tif err == nil && x != \"\" {\n\t\treturn x\n\t}\n\tlogrus.WithError(err).Debug(\"failed to get machine ID, falling back to use hostname instead\")\n\thostname, err := os.Hostname()\n\tif err != nil {\n\t\tpanic(fmt.Errorf(\"failed to get hostname: %w\", err))\n\t}\n\treturn hostname\n})\n\nfunc machineID(ctx context.Context) (string, error) {\n\tif runtime.GOOS == \"darwin\" {\n\t\tioPlatformExpertDeviceCmd := exec.CommandContext(ctx, \"/usr/sbin/ioreg\", \"-a\", \"-d2\", \"-c\", \"IOPlatformExpertDevice\")\n\t\tioPlatformExpertDevice, err := ioPlatformExpertDeviceCmd.CombinedOutput()\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\treturn parseIOPlatformUUIDFromIOPlatformExpertDevice(bytes.NewReader(ioPlatformExpertDevice))\n\t}\n\n\tcandidates := []string{\n\t\t\"/etc/machine-id\",\n\t\t\"/var/lib/dbus/machine-id\",\n\t\t// We don't use \"/sys/class/dmi/id/product_uuid\"","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/osutil/machineid.go#L14-L50","documentation":"Lima needs a stable machine identity for an instance and first tries the OS machine ID. When that fails it falls back to os.Hostname(); this panic wraps an error from that hostname lookup itself. It is thrown because a Go program can proceed with an empty/unknown hostname only at the risk of colliding identities, so the library aborts loudly.","triggerScenarios":"os.Hostname() returns a non-nil error during the fallback path of the lazy machineID resolution — i.e. the machine ID file was unreadable/empty AND the kernel hostname lookup failed.","commonSituations":"Running in a stripped-down container or chroot with no /etc/machine-id (or /etc/sysidcfg etc.) and a broken/unset UTS namespace; extremely restricted seccomp profiles blocking uname; corrupted /proc/sys/kernel/hostname on Linux.","solutions":["Ensure a valid machine ID exists (e.g. write a UUID to /etc/machine-id on Linux) so the hostname fallback is never reached.","Verify the container/VM has a proper UTS namespace and a set hostname (run `hostname` in the same environment).","If running in a restricted container, allow the uname/sethostname syscalls or run with a normal namespace (e.g. docker run without a custom seccomp profile).","As a last resort set a hostname explicitly in the environment before starting lima."],"exampleFix":"// before: container started with --security-opt seccomp=unconfined but no uts namespace\n// after: ensure machine-id exists so hostname fallback is not needed\n$ uuidgen > /etc/machine-id\n$ hostname myhost","handlingStrategy":"try-catch","validationCode":"// Linux: ensure a machine ID exists so the hostname fallback (and its panic) is never hit\nif _, err := os.Stat(\"/etc/machine-id\"); err != nil {\n    id, _ := uuid.NewRandom()\n    os.WriteFile(\"/etc/machine-id\", []byte(strings.ReplaceAll(id.String(), \"-\", \"\")), 0o444)\n}","typeGuard":null,"tryCatchPattern":"// error 860 is a panic, so use recover\nfunc safeMachineID() (id string, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"machine id panic: %v\", r)\n        }\n    }()\n    return osutil.MachineID(context.Background())\n}","preventionTips":["Provision /etc/machine-id in all container images used with lima","Verify `hostname` resolves without error in the deployment environment","Avoid hardened seccomp profiles that block uname in CI containers"],"tags":["hostname","machine-id","panic","linux"],"backgroundTag":"hostname-lookup-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}