{"record":{"id":"40bcc9d72554e949","repo":"thanos-io/thanos","slug":"lookup-srv-records-q","errorCode":null,"errorMessage":"lookup SRV records %q","messagePattern":"lookup SRV records %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/discovery/dns/resolver.go","lineNumber":102,"sourceCode":"\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}\n\n\t\tfor _, rec := range recs {\n\t\t\t// Only use port from SRV record if no explicit port was specified.\n\t\t\tresPort := port\n\t\t\tif resPort == \"\" {\n\t\t\t\tresPort = strconv.Itoa(int(rec.Port))\n\t\t\t}\n\n\t\t\tif qtype == SRVNoA {\n\t\t\t\t// Remove the final dot from rooted DNS names (this is for compatibility with Prometheus)\n\t\t\t\ttarget := strings.TrimRight(rec.Target, \".\")\n\t\t\t\tres = append(res, appendScheme(scheme, net.JoinHostPort(target, resPort)))\n\t\t\t\tcontinue","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/discovery/dns/resolver.go#L84-L120","documentation":"For qtype dnssrv/dnssrvnoa, Resolve calls LookupSRV for the host. Failures other than NotFound are wrapped as \"lookup SRV records <host>\" and returned, meaning the SRV query itself failed (as opposed to the record simply not existing).","triggerScenarios":"Resolve(ctx, \"_grpc._tcp.example.com\", \"dnssrv\") where the SRV query errors: DNS server unreachable, timeout, SERVFAIL, malformed response, or non-NotFound errors from the underlying resolver (including the SRV recursion-cap error from CNAME loops in SRV answers).","commonSituations":"Misconfigured SRV discovery names (querying a zone without SRV support via a server that errors rather than NXDOMAINs); DNS outage/firewall blocking UDP/TCP 53; rooted-name issues where the query target is wrong.","solutions":["Verify the SRV record exists and the server responds: dig SRV _service._proto.example.com","Check DNS server connectivity and timeouts; inspect errors.Cause of the wrapped error","Use qtype dns if the target is a plain A record rather than an SRV-based service","If NotFound was intended to be tolerated, confirm the name; NotFound is already tolerated and only logged"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check SRV availability\n_, recs, err := net.LookupSRV(\"\", \"\", srvName)\nif err != nil && !isNXDOMAIN(err) { /* SRV query will likely fail in the library too */ }","typeGuard":null,"tryCatchPattern":"res, err := resolver.Resolve(ctx, srvName, dns.SRV)\nif err != nil {\n    if strings.Contains(err.Error(), \"lookup SRV records\") {\n        cause := errors.Cause(err)\n        // log cause; retry on timeout, alert on persistent failure\n    }\n    return err\n}","preventionTips":["Verify SRV records with dig SRV before configuring discovery","Ensure the DNS server actually serves the SRV zone (some servers error instead of NXDOMAIN)","Keep SRV-answer CNAME chains short to avoid the recursion cap","Include the full _service._proto prefix in the configured name"],"tags":["dns","srv","network","lookup-failed"],"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"}