{"record":{"id":"99603ea0f5b3f83e","repo":"micro/go-micro","slug":"failed-to-bind-to-any-unicast-udp-port","errorCode":null,"errorMessage":"failed to bind to any unicast udp port","messagePattern":"failed to bind to any unicast udp port","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/mdns/client.go","lineNumber":190,"sourceCode":"\tclosedCh  chan struct{} // TODO(reddaly): This doesn't appear to be used.\n\tcloseLock sync.Mutex\n\n\tclosed bool\n}\n\n// NewClient creates a new mdns Client that can be used to query\n// for records.\nfunc newClient() (*client, error) {\n\t// TODO(reddaly): At least attempt to bind to the port required in the spec.\n\t// Create a IPv4 listener\n\tuconn4, err4 := net.ListenUDP(\"udp4\", &net.UDPAddr{IP: net.IPv4zero, Port: 0})\n\tuconn6, err6 := net.ListenUDP(\"udp6\", &net.UDPAddr{IP: net.IPv6zero, Port: 0})\n\tif err4 != nil && err6 != nil {\n\t\tlogger.Logf(logger.ErrorLevel, \"[mdns] failed to bind to udp port: %v %v\", err4, err6)\n\t}\n\n\tif uconn4 == nil && uconn6 == nil {\n\t\treturn nil, fmt.Errorf(\"failed to bind to any unicast udp port\")\n\t}\n\n\tif uconn4 == nil {\n\t\tuconn4 = &net.UDPConn{}\n\t}\n\n\tif uconn6 == nil {\n\t\tuconn6 = &net.UDPConn{}\n\t}\n\n\tmconn4, err4 := net.ListenUDP(\"udp4\", mdnsWildcardAddrIPv4)\n\tmconn6, err6 := net.ListenUDP(\"udp6\", mdnsWildcardAddrIPv6)\n\tif err4 != nil && err6 != nil {\n\t\tlogger.Logf(logger.ErrorLevel, \"[mdns] failed to bind to udp port: %v %v\", err4, err6)\n\t}\n\n\tif mconn4 == nil && mconn6 == nil {\n\t\treturn nil, fmt.Errorf(\"failed to bind to any multicast udp port\")","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/internal/util/mdns/client.go#L172-L208","documentation":"During newClient, the mDNS client tries to open unicast UDP sockets on both IPv4 (udp4) and IPv6 (udp6) wildcard addresses. If both ListenUDP calls fail, no unicast socket exists and construction aborts with this error. The individual bind errors are logged beforehand at ErrorLevel.","triggerScenarios":"newClient (invoked via Query or Listen) when net.ListenUDP fails for both udp4 and udp6 on port 0.","commonSituations":"Hosts with no network interfaces up; containers with networking disabled; resource exhaustion (out of file descriptors); sandboxed environments blocking socket creation.","solutions":["Check that at least one loopback or physical interface is up (ip link / ifconfig)","Verify available file descriptors (ulimit -n) and close leaked sockets","Confirm the environment permits UDP socket creation (containers, seccomp profiles)","Inspect the preceding '[mdns] failed to bind to udp port' log lines for the underlying OS error"],"exampleFix":"// diagnose before retry\nuconn, err := net.ListenUDP(\"udp4\", &net.UDPAddr{IP: net.IPv4zero, Port: 0})\nif err != nil {\n    log.Fatalf(\"cannot create UDP socket: %v — check interfaces/ulimit\", err)\n}","handlingStrategy":"try-catch","validationCode":"// preflight: can we open any unicast UDP socket?\nprobe, err := net.ListenUDP(\"udp4\", &net.UDPAddr{IP: net.IPv4zero, Port: 0})\nif err != nil {\n    log.Fatalf(\"unicast UDP unavailable: %v\", err)\n}\nprobe.Close()","typeGuard":null,"tryCatchPattern":"c, err := mdns.NewClient(config)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to bind to any unicast udp port\") {\n        // fall back to non-mdns discovery or surface a network-environment problem\n        return nil, fmt.Errorf(\"mdns unavailable: check interfaces/fd limits: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Verify network interfaces are up before starting service discovery","Keep fd limits comfortably high in containers (ulimit -n)","Avoid running discovery inside sandboxes that block socket creation"],"tags":["network","udp","mdns"],"backgroundTag":"udp-bind-failure","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}