micro/go-micro · error
mdns: error sending unicast response: %v
Error message
mdns: error sending unicast response: %v
What it means
This error is returned by handleQuery when the mDNS server failed to write a unicast DNS response packet back to the client's address via sendResponse. It wraps the underlying UDP socket write error (which is included via %v). It indicates the query was parsed and an answer was generated, but delivering that answer over the network failed.
Source
Thrown at internal/util/mdns/server.go:314
// 18.13 pertains to resource records (handled by handleQuestion)
// 18.14: Name Compression - responses should be compressed (though see
// caveats in the RFC), so set the Compress bit (part of the dns library
// API, not part of the DNS packet) to true.
Compress: true,
Question: query.Question,
Answer: answer,
}
}
if mresp := resp(false); mresp != nil {
if err := s.sendResponse(mresp, from); err != nil {
return fmt.Errorf("mdns: error sending multicast response: %v", err)
}
}
if uresp := resp(true); uresp != nil {
if err := s.sendResponse(uresp, from); err != nil {
return fmt.Errorf("mdns: error sending unicast response: %v", err)
}
}
return nil
}
// handleQuestion is used to handle an incoming question
//
// The response to a question may be transmitted over multicast, unicast, or
// both. The return values are DNS records for each transmission type.
func (s *Server) handleQuestion(q dns.Question) (multicastRecs, unicastRecs []dns.RR) {
records := s.config.Zone.Records(q)
if len(records) == 0 {
return nil, nil
}
// Handle unicast and multicast responses.
// TODO(reddaly): The decision about sending over unicast vs. multicast is not
// yet fully compliant with RFC 6762. For example, the unicast bit should beView on GitHub (pinned to 24529f1404)
Solutions
- Read the wrapped %v cause to identify the socket error (e.g. 'connection refused', 'message too long', 'network is unreachable') and fix the underlying network condition
- Check that the replying host's network interface is up and multicast/unicast UDP on port 5353 is permitted by the firewall
- Ensure the mDNS server is not being shut down while queries are still in flight; stop the server cleanly before closing sockets
- If responses exceed the MTU, reduce the size of records in the zone (fewer TXT entries, fewer IPs) or rely on multicast with truncation handling
Example fix
// before: blindly treating any send failure as fatal
if err := s.sendResponse(uresp, from); err != nil {
return fmt.Errorf("mdns: error sending unicast response: %v", err)
}
// after: tolerate transient client-gone errors
if err := s.sendResponse(uresp, from); err != nil {
log.Printf("mdns: skipping unicast response to %v: %v", from, err)
} Defensive patterns
Strategy: try-catch
Validate before calling
// Check socket/network readiness before serving
conn, err := net.ListenMulticastUDP("udp4", nil, mdnsAddr)
if err != nil { return err }
// ensure interface is up
ifaces, _ := net.Interfaces()
up := false
for _, i := range ifaces {
if i.Flags&net.FlagUp != 0 && i.Flags&net.FlagRunning != 0 { up = true }
}
if !up { return errors.New("no active network interface") } Type guard
func isSendErr(err error) bool {
return err != nil && strings.Contains(err.Error(), "error sending unicast response")
} Try / catch
err := server.HandleQuery(...)
if err != nil {
if isSendErr(err) {
log.Printf("mdns unicast response failed (client may be gone): %v", err)
return // tolerate; query senders time out and retry via multicast
}
return err
} Prevention
- Never treat unicast-response failures as fatal — the querying peer may have disappeared
- Keep responses under the UDP/MTU size limit to avoid 'message too long'
- Allow UDP 5353 in host firewalls and stop the server cleanly before closing sockets
When it happens
Trigger: Calling s.sendResponse(uresp, from) with a unicast (resp(true)) response inside handleQuery returns a non-nil error, e.g. the socket write to the source address fails (network unreachable, ICMP port unreachable, interface down, or socket closed).
Common situations: The client that sent the query has already shut down its socket or left the network; the response is larger than the path MTU and gets dropped with 'message too long'; a firewall blocks UDP from the mDNS port; the machine's network interface went down mid-query.
Related errors
- failed to bind to any unicast udp port
- failed to bind to any multicast udp port
- [ERR] mdns: Failed to bind to any udp port
- mdns: error sending multicast 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/2ce7838a87b2e1e1.
Report an issue: GitHub.