{"record":{"id":"e78241da33e85ed4","repo":"thanos-io/thanos","slug":"lookup-ip-addresses-q","errorCode":null,"errorMessage":"lookup IP addresses %q","messagePattern":"lookup IP addresses %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/discovery/dns/resolver.go","lineNumber":89,"sourceCode":"\t// Split the host and port if present.\n\thost, port, err := net.SplitHostPort(name)\n\tif err != nil {\n\t\t// The host could be missing a port.\n\t\thost, port = name, \"\"\n\t}\n\n\tswitch qtype {\n\tcase A:\n\t\tif port == \"\" {\n\t\t\treturn nil, errors.Errorf(\"missing port in address given for dns lookup: %v\", name)\n\t\t}\n\t\tips, err := s.resolver.LookupIPAddr(ctx, host)\n\t\tif err != nil {\n\t\t\t// We exclude error from std Golang resolver for the case of the domain (e.g `NXDOMAIN`) not being found by DNS\n\t\t\t// server. Since `miekg` does not consider this as an error,  when the host cannot be found, empty slice will be\n\t\t\t// returned.\n\t\t\tif !s.resolver.IsNotFound(err) {\n\t\t\t\treturn nil, errors.Wrapf(err, \"lookup IP addresses %q\", host)\n\t\t\t}\n\t\t\tif ips == nil {\n\t\t\t\tlevel.Error(s.logger).Log(\"msg\", \"failed to lookup IP addresses\", \"host\", host, \"err\", err)\n\t\t\t}\n\t\t}\n\t\tfor _, ip := range ips {\n\t\t\tres = append(res, appendScheme(scheme, net.JoinHostPort(ip.String(), port)))\n\t\t}\n\tcase SRV, SRVNoA:\n\t\t_, recs, err := s.resolver.LookupSRV(ctx, \"\", \"\", host)\n\t\tif err != nil {\n\t\t\tif !s.resolver.IsNotFound(err) {\n\t\t\t\treturn nil, errors.Wrapf(err, \"lookup SRV records %q\", host)\n\t\t\t}\n\t\t\tif len(recs) == 0 {\n\t\t\t\tlevel.Error(s.logger).Log(\"msg\", \"failed to lookup SRV records\", \"host\", host, \"err\", err)\n\t\t\t}\n\t\t}","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/discovery/dns/resolver.go#L71-L107","documentation":"After LookupIPAddr fails on the A/AAAA path, Resolve only swallows the error when the resolver classifies it as NotFound (NXDOMAIN-style). Any other lookup failure is wrapped with \"lookup IP addresses <host>\" and returned, indicating a real DNS/network problem rather than a missing record.","triggerScenarios":"Resolve(ctx, name, A) where the underlying resolver's LookupIPAddr returns a non-NotFound error: DNS server unreachable/timeout, SERVFAIL, network partition, or the iteration-cap/CNAME errors from the miekg resolver.","commonSituations":"DNS server down or firewalled (port 53 blocked); /etc/resolv.conf pointing at an unresponsive nameserver; SERVFAIL from an upstream zone; CNAME loops triggering the recursion cap during service discovery.","solutions":["Check DNS server reachability: dig/nslookup the host with the configured nameserver","Inspect the wrapped inner error (errors.Cause) for the root cause (timeout, SERVFAIL, recursion cap)","Fix /etc/resolv.conf or the resolver's ResolvConf path if nameservers are wrong","Retry with backoff for transient network failures; fix CNAME loops in the zone if that is the cause"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := net.LookupHost(host); err != nil {\n    var dnsErr *net.DNSError\n    if errors.As(err, &dnsErr) && dnsErr.IsNotFound { /* NXDOMAIN: skip, not a network problem */ }\n}","typeGuard":null,"tryCatchPattern":"res, err := resolver.Resolve(ctx, name, dns.A)\nif err != nil {\n    cause := errors.Cause(err)\n    if errors.Is(cause, miekgdns.ErrNoSuchHost) { /* tolerated: record missing */ }\n    if ne, ok := cause.(net.Error); ok && ne.Timeout() { /* retry with backoff */ }\n    return err\n}","preventionTips":["Monitor nameserver reachability (port 53) from the discovery process","Keep /etc/resolv.conf or ResolvConf correct","Distinguish NotFound from real failures via IsNotFound / errors.Cause","Add retry with backoff for transient DNS timeouts"],"tags":["dns","network","lookup-failed","wrapped-error"],"backgroundTag":"dns-resolution-failed","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}