micro/go-micro · error
[ERR] mdns: Failed to bind to any udp port
Error message
[ERR] mdns: Failed to bind to any udp port
What it means
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.
Source
Thrown at internal/util/mdns/server.go:94
outboundIP net.IP
wg sync.WaitGroup
shutdownLock sync.Mutex
shutdown bool
}
// NewServer is used to create a new mDNS server from a config.
func NewServer(config *Config) (*Server, error) {
setCustomPort(config.Port)
// Create the listeners
// Create wildcard connections (because :5353 can be already taken by other apps)
ipv4List, _ := net.ListenUDP("udp4", mdnsWildcardAddrIPv4)
ipv6List, _ := net.ListenUDP("udp6", mdnsWildcardAddrIPv6)
if ipv4List == nil && ipv6List == nil {
return nil, fmt.Errorf("[ERR] mdns: Failed to bind to any udp port")
}
if ipv4List == nil {
ipv4List = &net.UDPConn{}
}
if ipv6List == nil {
ipv6List = &net.UDPConn{}
}
// Join multicast groups to receive announcements
p1 := ipv4.NewPacketConn(ipv4List)
p2 := ipv6.NewPacketConn(ipv6List)
_ = p1.SetMulticastLoopback(true)
_ = p2.SetMulticastLoopback(true)
if config.Iface != nil {
if err := p1.JoinGroup(config.Iface, &net.UDPAddr{IP: mdnsGroupIPv4}); err != nil {
return nil, errView on GitHub (pinned to 24529f1404)
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
Example fix
// before: bind fails because Avahi holds :5353
srv, err := mdns.NewServer(&mdns.Config{Zone: zone})
// after: free the port first
// $ sudo systemctl stop avahi-daemon
srv, err := mdns.NewServer(&mdns.Config{Zone: zone}) Defensive patterns
Strategy: fallback
Validate before calling
l4, err4 := net.ListenUDP("udp4", &net.UDPAddr{IP: net.IPv4zero, Port: 5353})
l6, err6 := net.ListenUDP("udp6", &net.UDPAddr{IP: net.IPv6zero, Port: 5353})
if l4 == nil && l6 == nil {
log.Fatalf("port 5353 unusable: %v %v", err4, err6)
}
if l4 != nil { l4.Close() }
if l6 != nil { l6.Close() } Try / catch
srv, err := mdns.NewServer(&mdns.Config{Zone: zone})
if err != nil {
if strings.Contains(err.Error(), "Failed to bind to any udp port") {
return nil, fmt.Errorf("mDNS server cannot start: is another mDNS daemon holding :5353? %w", err)
}
return nil, err
} Prevention
- 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
When it happens
Trigger: NewServer (used by Register and tests) when both net.ListenUDP("udp4", ...) and net.ListenUDP("udp6", ...) return nil connections.
Common situations: Port 5353 occupied by another mDNS daemon (Avahi, Bonjour) without reuse options; firewalls/SELinux blocking binds; out-of-file-descriptor conditions in test environments.
Related errors
- failed to bind to any unicast udp port
- failed to bind to any multicast udp port
- mdns: error sending multicast response: %v
- mdns: error sending unicast response: %v
- failed to join multicast group on all interfaces
AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01).
Data as JSON: /api/errors/545442ad1400ad61.
Report an issue: GitHub.