{"record":{"id":"2ce7838a87b2e1e1","repo":"micro/go-micro","slug":"mdns-error-sending-unicast-response-v","errorCode":null,"errorMessage":"mdns: error sending unicast response: %v","messagePattern":"mdns: error sending unicast response: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/mdns/server.go","lineNumber":314,"sourceCode":"\t\t\t// 18.13 pertains to resource records (handled by handleQuestion)\n\n\t\t\t// 18.14: Name Compression - responses should be compressed (though see\n\t\t\t// caveats in the RFC), so set the Compress bit (part of the dns library\n\t\t\t// API, not part of the DNS packet) to true.\n\t\t\tCompress: true,\n\t\t\tQuestion: query.Question,\n\t\t\tAnswer:   answer,\n\t\t}\n\t}\n\n\tif mresp := resp(false); mresp != nil {\n\t\tif err := s.sendResponse(mresp, from); err != nil {\n\t\t\treturn fmt.Errorf(\"mdns: error sending multicast response: %v\", err)\n\t\t}\n\t}\n\tif uresp := resp(true); uresp != nil {\n\t\tif err := s.sendResponse(uresp, from); err != nil {\n\t\t\treturn fmt.Errorf(\"mdns: error sending unicast response: %v\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// handleQuestion is used to handle an incoming question\n//\n// The response to a question may be transmitted over multicast, unicast, or\n// both.  The return values are DNS records for each transmission type.\nfunc (s *Server) handleQuestion(q dns.Question) (multicastRecs, unicastRecs []dns.RR) {\n\trecords := s.config.Zone.Records(q)\n\tif len(records) == 0 {\n\t\treturn nil, nil\n\t}\n\n\t// Handle unicast and multicast responses.\n\t// TODO(reddaly): The decision about sending over unicast vs. multicast is not\n\t// yet fully compliant with RFC 6762.  For example, the unicast bit should be","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/internal/util/mdns/server.go#L296-L332","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before: blindly treating any send failure as fatal\nif err := s.sendResponse(uresp, from); err != nil {\n\treturn fmt.Errorf(\"mdns: error sending unicast response: %v\", err)\n}\n// after: tolerate transient client-gone errors\nif err := s.sendResponse(uresp, from); err != nil {\n\tlog.Printf(\"mdns: skipping unicast response to %v: %v\", from, err)\n}","handlingStrategy":"try-catch","validationCode":"// Check socket/network readiness before serving\nconn, err := net.ListenMulticastUDP(\"udp4\", nil, mdnsAddr)\nif err != nil { return err }\n// ensure interface is up\nifaces, _ := net.Interfaces()\nup := false\nfor _, i := range ifaces {\n\tif i.Flags&net.FlagUp != 0 && i.Flags&net.FlagRunning != 0 { up = true }\n}\nif !up { return errors.New(\"no active network interface\") }","typeGuard":"func isSendErr(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"error sending unicast response\")\n}","tryCatchPattern":"err := server.HandleQuery(...)\nif err != nil {\n\tif isSendErr(err) {\n\t\tlog.Printf(\"mdns unicast response failed (client may be gone): %v\", err)\n\t\treturn // tolerate; query senders time out and retry via multicast\n\t}\n\treturn err\n}","preventionTips":["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"],"tags":["network","mdns","udp","socket-write"],"backgroundTag":"udp-send-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}