{"record":{"id":"545442ad1400ad61","repo":"micro/go-micro","slug":"err-mdns-failed-to-bind-to-any-udp-port","errorCode":null,"errorMessage":"[ERR] mdns: Failed to bind to any udp port","messagePattern":"\\[ERR\\] mdns: Failed to bind to any udp port","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/mdns/server.go","lineNumber":94,"sourceCode":"\n\toutboundIP net.IP\n\twg         sync.WaitGroup\n\n\tshutdownLock sync.Mutex\n\n\tshutdown bool\n}\n\n// NewServer is used to create a new mDNS server from a config.\nfunc NewServer(config *Config) (*Server, error) {\n\tsetCustomPort(config.Port)\n\n\t// Create the listeners\n\t// Create wildcard connections (because :5353 can be already taken by other apps)\n\tipv4List, _ := net.ListenUDP(\"udp4\", mdnsWildcardAddrIPv4)\n\tipv6List, _ := net.ListenUDP(\"udp6\", mdnsWildcardAddrIPv6)\n\tif ipv4List == nil && ipv6List == nil {\n\t\treturn nil, fmt.Errorf(\"[ERR] mdns: Failed to bind to any udp port\")\n\t}\n\n\tif ipv4List == nil {\n\t\tipv4List = &net.UDPConn{}\n\t}\n\tif ipv6List == nil {\n\t\tipv6List = &net.UDPConn{}\n\t}\n\n\t// Join multicast groups to receive announcements\n\tp1 := ipv4.NewPacketConn(ipv4List)\n\tp2 := ipv6.NewPacketConn(ipv6List)\n\t_ = p1.SetMulticastLoopback(true)\n\t_ = p2.SetMulticastLoopback(true)\n\n\tif config.Iface != nil {\n\t\tif err := p1.JoinGroup(config.Iface, &net.UDPAddr{IP: mdnsGroupIPv4}); err != nil {\n\t\t\treturn nil, err","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/internal/util/mdns/server.go#L76-L112","documentation":"NewServer creates wildcard UDP listeners for mDNS on port 5353 for both IPv4 and IPv6. If neither listen succeeds, the server cannot receive mDNS packets and returns this error. Individual listen errors are discarded, so only the combined failure is reported.","triggerScenarios":"NewServer (used by Register and tests) when both net.ListenUDP(\"udp4\", ...) and net.ListenUDP(\"udp6\", ...) return nil connections.","commonSituations":"Port 5353 occupied by another mDNS daemon (Avahi, Bonjour) without reuse options; firewalls/SELinux blocking binds; out-of-file-descriptor conditions in test environments.","solutions":["Stop competing mDNS services holding :5353 (systemctl stop avahi-daemon) or confirm reuse flags are set on both sides","Check OS-level restrictions (SELinux, AppArmor, firewall) that block binding UDP 5353","Increase fd limits if descriptors are exhausted (ulimit -n)","Run as a user/group with permission to bind multicast ports"],"exampleFix":"// before: bind fails because Avahi holds :5353\nsrv, err := mdns.NewServer(&mdns.Config{Zone: zone})\n// after: free the port first\n// $ sudo systemctl stop avahi-daemon\nsrv, err := mdns.NewServer(&mdns.Config{Zone: zone})","handlingStrategy":"fallback","validationCode":"l4, err4 := net.ListenUDP(\"udp4\", &net.UDPAddr{IP: net.IPv4zero, Port: 5353})\nl6, err6 := net.ListenUDP(\"udp6\", &net.UDPAddr{IP: net.IPv6zero, Port: 5353})\nif l4 == nil && l6 == nil {\n    log.Fatalf(\"port 5353 unusable: %v %v\", err4, err6)\n}\nif l4 != nil { l4.Close() }\nif l6 != nil { l6.Close() }","typeGuard":null,"tryCatchPattern":"srv, err := mdns.NewServer(&mdns.Config{Zone: zone})\nif err != nil {\n    if strings.Contains(err.Error(), \"Failed to bind to any udp port\") {\n        return nil, fmt.Errorf(\"mDNS server cannot start: is another mDNS daemon holding :5353? %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Disable or reconfigure Avahi/Bonjour on hosts running this server","Check port 5353 occupancy before startup (lsof -i :5353)","Bump fd limits and verify firewall/SELinux allows UDP 5353"],"tags":["network","udp","mdns","port-in-use"],"backgroundTag":"port-already-in-use","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}