{"record":{"id":"3dc017133a91d408","repo":"grpc/grpc-go","slug":"delegating-resolver-invalid-target-address-q-v","errorCode":null,"errorMessage":"delegating_resolver: invalid target address %q: %v","messagePattern":"delegating_resolver: invalid target address %q: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/resolver/delegatingresolver/delegatingresolver.go","lineNumber":119,"sourceCode":"//     in the target URI or specified by the user using the WithResolvers dial\n//     option. As a special case, if the target URI's scheme is \"dns\" and a\n//     proxy is specified using the supported environment variables, the target\n//     URI's path portion is used as the resolved address unless target\n//     resolution is enabled using the dial option.\nfunc New(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions, targetResolverBuilder resolver.Builder, targetResolutionEnabled bool) (resolver.Resolver, error) {\n\tr := &delegatingResolver{\n\t\ttarget:         target,\n\t\tcc:             cc,\n\t\tproxyResolver:  nopResolver{},\n\t\ttargetResolver: nopResolver{},\n\t}\n\n\taddr := target.Endpoint()\n\tvar err error\n\tif target.URL.Scheme == \"dns\" && !targetResolutionEnabled && envconfig.EnableDefaultPortForProxyTarget {\n\t\taddr, err = parseTarget(addr)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"delegating_resolver: invalid target address %q: %v\", target.Endpoint(), err)\n\t\t}\n\t}\n\n\tr.proxyURL, err = proxyURLForTarget(addr)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"delegating_resolver: failed to determine proxy URL for target %q: %v\", target, err)\n\t}\n\n\t// proxy is not configured or proxy address excluded using `NO_PROXY` env\n\t// var, so only target resolver is used.\n\tif r.proxyURL == nil {\n\t\treturn targetResolverBuilder.Build(target, cc, opts)\n\t}\n\n\tif logger.V(2) {\n\t\tlogger.Infof(\"Proxy URL detected : %s\", r.proxyURL)\n\t}\n","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/grpc/grpc-go/blob/03255a9237b6eb32710f6bc4f2de9a675b99fe36/internal/resolver/delegatingresolver/delegatingresolver.go#L101-L137","documentation":"Returned by the delegating resolver's New() when, for a dns-scheme target with target resolution disabled and EnableDefaultPortForProxyTarget set, parseTarget(addr) fails. parseTarget rejects empty addresses and addresses ending in a colon with no port. The error is returned from resolver construction and surfaces as a dial failure.","triggerScenarios":"Dialing a dns:/// target whose endpoint is empty or malformed (e.g. \"dns:///:\", \"dns:///host:\") while a proxy is configured via HTTPS_PROXY and the feature flag EnableDefaultPortForProxyTarget is on.","commonSituations":"Constructing the dial target string dynamically and leaving the host blank; trailing colon from string concatenation; misconfigured target builder that drops the host portion.","solutions":["Provide a non-empty host (and a valid port or no port) in the target: \"dns:///host:443\" or \"dns:///host\".","Audit the code that assembles the target URI to avoid trailing colons or empty endpoints.","Disable the EnableDefaultPortForProxyTarget experiment if it is not needed."],"exampleFix":"// before\nconn, _ := grpc.Dial(\"dns:///:\", ...) // -> invalid target address\n// after\nconn, _ := grpc.Dial(\"dns:///my-service:443\", ...)","handlingStrategy":"validation","validationCode":"// Validate the target endpoint before dialing.\nfunc validTarget(t string) error {\n    ep := strings.TrimPrefix(t, \"dns:///\")\n    if ep == \"\" || strings.HasSuffix(ep, \":\") {\n        return fmt.Errorf(\"bad target %q\", t)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"conn, err := grpc.Dial(target, ...)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid target address\") {\n        return fmt.Errorf(\"fix target URI %q: %w\", target, err)\n    }\n}","preventionTips":["Build dns targets with a single helper that always emits host or host:port.","Reject empty/trailing-colon endpoints at config-load time.","Log the exact target string when a dial fails."],"tags":["grpc","resolver","delegating-resolver","proxy","dns","target-uri"],"analyzedSha":"03255a9237b6eb32710f6bc4f2de9a675b99fe36","analyzedAt":"2026-08-07T00:29:34.215Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}