{"record":{"id":"dfa124dda45d7808","repo":"lima-vm/lima","slug":"expected-net-udpaddr-got-v","errorCode":null,"errorMessage":"expected *net.UDPAddr, got %v","messagePattern":"expected \\*net\\.UDPAddr, got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/freeport/freeport.go","lineNumber":47,"sourceCode":"\t\treturn 0, fmt.Errorf(\"unexpected port %d\", port)\n\t}\n\treturn port, nil\n}\n\nfunc UDP() (int, error) {\n\tlAddr0, err := net.ResolveUDPAddr(\"udp4\", \"127.0.0.1:0\")\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tl, err := net.ListenUDP(\"udp4\", lAddr0)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tdefer l.Close()\n\tlAddr := l.LocalAddr()\n\tlUDPAddr, ok := lAddr.(*net.UDPAddr)\n\tif !ok {\n\t\treturn 0, fmt.Errorf(\"expected *net.UDPAddr, got %v\", lAddr)\n\t}\n\tport := lUDPAddr.Port\n\tif port <= 0 {\n\t\treturn 0, fmt.Errorf(\"unexpected port %d\", port)\n\t}\n\treturn port, nil\n}\n","sourceCodeStart":29,"sourceCodeEnd":55,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/freeport/freeport.go#L29-L55","documentation":"freeport.UDP() binds a UDP socket on 127.0.0.1:0 and asserts l.LocalAddr() is a *net.UDPAddr to extract the assigned port. If the returned net.Addr is of another concrete type, this error is thrown. Like its TCP counterpart it should be unreachable on standard platforms.","triggerScenarios":"Calling freeport.UDP() when the PacketConn's LocalAddr() returns a non-UDPAddr implementation, e.g. under unusual network stacks, middleware, or a refactored code path passing a wrapped connection.","commonSituations":"Rare; seen when running under custom network instrumentation or when Go/OS network behavior changes. Also reproducible with wrapped/mocked PacketConn implementations in tests.","solutions":["Retry freeport.UDP() once.","Ensure no network wrapping/instrumentation is intercepting UDP sockets.","Upgrade Go to a current release to rule out stdlib regressions.","As a workaround, bind manually with net.ListenUDP(\"udp4\", &net.UDPAddr{IP: net.IPv4(127,0,0,1)}) and read the port from the returned *net.UDPAddr."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"if udpAddr, ok := l.LocalAddr().(*net.UDPAddr); !ok { return 0, fmt.Errorf(\"expected *net.UDPAddr, got %v\", l.LocalAddr()) }","tryCatchPattern":"port, err := freeport.UDP()\nif err != nil {\n    // fallback: manual UDP bind\n    conn, lerr := net.ListenUDP(\"udp4\", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1)})\n    if lerr != nil { return fmt.Errorf(\"freeport.UDP failed: %w\", err) }\n    defer conn.Close()\n    port = conn.LocalAddr().(*net.UDPAddr).Port\n}","preventionTips":["Do not wrap PacketConn with custom LocalAddr implementations","Keep Go toolchain up to date","Test UDP allocation in the target sandbox environment"],"tags":["network","udp","freeport","type-assertion"],"backgroundTag":"unexpected-net-addr-type","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}