{"record":{"id":"e7f5e8b058808c5e","repo":"lima-vm/lima","slug":"freeport-vsock-is-not-implemented-for-non-windows","errorCode":null,"errorMessage":"freeport.VSock is not implemented for non-Windows hosts","messagePattern":"freeport\\.VSock is not implemented for non-Windows hosts","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/freeport/freeport_unix.go","lineNumber":11,"sourceCode":"//go:build !windows\n\n// SPDX-FileCopyrightText: Copyright The Lima Authors\n// SPDX-License-Identifier: Apache-2.0\n\npackage freeport\n\nimport \"errors\"\n\nfunc VSock() (int, error) {\n\treturn 0, errors.New(\"freeport.VSock is not implemented for non-Windows hosts\")\n}\n","sourceCodeStart":1,"sourceCodeEnd":13,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/freeport/freeport_unix.go#L1-L13","documentation":"On non-Windows hosts freeport.VSock() is a stub that always returns this error, because vsock (AF_VSOCK) port probing is only implemented for Windows hosts in this codebase. Callers (e.g. Lima instance setup) hit it when the vsock-based free-port discovery path is taken on macOS or Linux.","triggerScenarios":"Calling freeport.VSock() directly, or driving the Lima instance-creation path (New) that consults VSock() for a free vsock port, on any host where runtime.GOOS != \"windows\".","commonSituations":"Running Lima code paths that expect the Windows vsock port allocator on a macOS or Linux host; tests or tooling invoking VSock() unconditionally instead of guarding on GOOS.","solutions":["Only call freeport.VSock() when runtime.GOOS == \"windows\"; use TCP()/UDP() elsewhere.","Gate the feature that needs a vsock port on host OS, and skip or stub it on non-Windows.","If vsock probing is genuinely needed on Linux/macOS, implement a platform-specific VSock() (e.g. bind to an AF_VSOCK socket on port 0)."],"exampleFix":"// before\nport, err := freeport.VSock()\n// after\nvar port int\nvar err error\nif runtime.GOOS == \"windows\" {\n    port, err = freeport.VSock()\n} else {\n    port, err = freeport.TCP()\n}","handlingStrategy":"validation","validationCode":"if runtime.GOOS != \"windows\" {\n    return errors.New(\"vsock port probing is only available on Windows hosts\")\n}","typeGuard":"func vsockSupported() bool { return runtime.GOOS == \"windows\" }","tryCatchPattern":"if !vsockSupported() {\n    // use TCP()/UDP() fallback\n    port, err = freeport.TCP()\n} else {\n    port, err = freeport.VSock()\n}","preventionTips":["Always gate freeport.VSock() behind runtime.GOOS == \"windows\"","Use build tags for platform-specific port allocation code","Add a unit test asserting VSock() is only exercised on Windows"],"tags":["freeport","vsock","platform-support","windows"],"backgroundTag":"not-implemented-for-platform","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}