{"record":{"id":"a92ae68f22ccf8f0","repo":"thanos-io/thanos","slug":"missing-port-in-address-given-for-dns-lookup-v","errorCode":null,"errorMessage":"missing port in address given for dns lookup: %v","messagePattern":"missing port in address given for dns lookup: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/discovery/dns/resolver.go","lineNumber":81,"sourceCode":"\t)\n\n\tschemeSplit := strings.Split(name, \"//\")\n\tif len(schemeSplit) > 1 {\n\t\tscheme = schemeSplit[0]\n\t\tname = schemeSplit[1]\n\t}\n\n\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)","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/discovery/dns/resolver.go#L63-L99","documentation":"The dnsSD Resolver's Resolve method with qtype dns requires a host:port address because results are rebuilt as ip:port. If the name carries no port (SplitHostPort left port empty), the lookup is refused up-front with this error before any DNS query.","triggerScenarios":"Calling Resolve(ctx, name, A) where name has no \":port\" suffix — e.g. Resolve(ctx, \"prometheus.example.com\", \"dns\") or \"http://prometheus.example.com\". Also happens when the scheme split eats the port or the name is malformed such that no port is parsed.","commonSituations":"Static SD configs listing bare hostnames without ports; copying an SRV-style entry (no port needed there) into a dns qtype entry; templated configs where the port variable is empty.","solutions":["Append the port to the name: use \"host:9090\" form, e.g. \"prometheus.example.com:9090\"","Use qtype dnssrv/dnssrvnoa instead of dns if the port should come from SRV records","Fix template/config so the port placeholder is populated","Remember a scheme prefix is allowed (\"http://host:9090\") but the port itself is still required"],"exampleFix":"// before\naddresses: [\"prometheus.example.com\"]  // qtype dns\n// after\naddresses: [\"prometheus.example.com:9090\"]  // qtype dns","handlingStrategy":"validation","validationCode":"_, _, err := net.SplitHostPort(name)\nif err != nil { return fmt.Errorf(\"dns qtype requires host:port, got %q\", name) }","typeGuard":null,"tryCatchPattern":"res, err := resolver.Resolve(ctx, name, dns.A)\nif err != nil {\n    if strings.Contains(err.Error(), \"missing port in address\") {\n        // fix config: append :port or switch to dnssrv qtype\n    }\n    return err\n}","preventionTips":["Always write host:port in static SD addresses for qtype dns","Use dnssrv/dnssrvnoa when ports come from SRV records","Validate address templates render with a non-empty port","A scheme prefix is fine but does not replace the port"],"tags":["dns","config","missing-port","go"],"backgroundTag":"missing-required-argument","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"}