{"record":{"id":"8814e66c484bac82","repo":"grpc/grpc-go","slug":"dns-resolver-missing-address","errorCode":null,"errorMessage":"dns resolver: missing address","messagePattern":"dns resolver: missing address","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/resolver/dns/internal/internal.go","lineNumber":41,"sourceCode":"\t\"context\"\n\t\"errors\"\n\t\"net\"\n\t\"time\"\n)\n\n// NetResolver groups the methods on net.Resolver that are used by the DNS\n// resolver implementation. This allows the default net.Resolver instance to be\n// overridden from tests.\ntype NetResolver interface {\n\tLookupHost(ctx context.Context, host string) (addrs []string, err error)\n\tLookupSRV(ctx context.Context, service, proto, name string) (cname string, addrs []*net.SRV, err error)\n\tLookupTXT(ctx context.Context, name string) (txts []string, err error)\n}\n\nvar (\n\t// ErrMissingAddr is the error returned when building a DNS resolver when\n\t// the provided target name is empty.\n\tErrMissingAddr = errors.New(\"dns resolver: missing address\")\n\n\t// ErrEndsWithColon is the error returned when building a DNS resolver when\n\t// the provided target name ends with a colon that is supposed to be the\n\t// separator between host and port.  E.g. \"::\" is a valid address as it is\n\t// an IPv6 address (host only) and \"[::]:\" is invalid as it ends with a\n\t// colon as the host and port separator\n\tErrEndsWithColon = errors.New(\"dns resolver: missing port after port-separator colon\")\n)\n\n// The following vars are overridden from tests.\nvar (\n\t// TimeAfterFunc is used by the DNS resolver to wait for the given duration\n\t// to elapse. In non-test code, this is implemented by time.After. In test\n\t// code, this can be used to control the amount of time the resolver is\n\t// blocked waiting for the duration to elapse.\n\tTimeAfterFunc func(time.Duration) <-chan time.Time\n\n\t// TimeNowFunc is used by the DNS resolver to get the current time.","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/internal/resolver/dns/internal/internal.go#L23-L59","documentation":"ErrMissingAddr is returned by the DNS resolver builder when the target address is empty. The DNS resolver needs a hostname to resolve; an empty string cannot be looked up. This error is defined in internal/resolver/dns/internal/internal.go and checked at the start of the resolver's Build function.","triggerScenarios":"Dialing gRPC with a dns:// scheme (or default resolver) where the target is empty: grpc.Dial(\"\") or grpc.Dial(\"dns:///\") . Also triggered when the target string is reduced to empty after scheme/authority stripping.","commonSituations":"Empty or uninitialized target variable passed to grpc.Dial; misconfigured service discovery that produces an empty address; environment variable for the server address unset, resulting in an empty dial target; DNS URI like 'dns:///' with no host.","solutions":["Provide a non-empty hostname in the dial target: grpc.Dial(\"dns:///my-service:8080\").","Validate the address is non-empty before dialing.","Check environment variables or config files that supply the target are set and non-empty.","Log the resolved target string to catch empty values early."],"exampleFix":"// before\nconn, err := grpc.Dial(os.Getenv(\"GRPC_TARGET\")) // empty if unset\n// after\ntarget := os.Getenv(\"GRPC_TARGET\")\nif target == \"\" {\n    log.Fatal(\"GRPC_TARGET must be set\")\n}\nconn, err := grpc.Dial(target)","handlingStrategy":"validation","validationCode":"// Validate the dial target is non-empty before dialing.\ntarget := os.Getenv(\"GRPC_TARGET\")\nif strings.TrimSpace(target) == \"\" {\n    log.Fatal(\"dial target is empty; set GRPC_TARGET\")\n}\nconn, err := grpc.Dial(target)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate address strings are non-empty before passing to grpc.Dial.","Set defaults for environment variables that supply dial targets.","Log the resolved target to catch empty values early.","Use config validation at startup to fail fast on empty addresses."],"tags":["dns","resolver","dial-target","validation","grpc"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}