Skip to content

Conversation

@jdcormie
Copy link
Member

@jdcormie jdcormie commented Jan 9, 2026

Accept both absolute (e.g. dns:///hostname) and rootless (e.g. dns:hostname) paths as specified by https://github.com/grpc/grpc/blob/master/doc/naming.md and matching the behavior of grpc core and grpc-go.

Add examples to the getPathSegments() javadoc.

Introduce RFC 3986 concepts of absolute and rootless paths.
Update javadoc/tests to match reality w.r.t target URI path: path isn't
actually the name to resolve, only the first path segment is actually
used. This is a side effect of authority parsing later, in
DnsNameResolver.java. Any additional path segments are silently ignored.

Replace discussion of the leading path / by making explicit the
requirement that the input java.net.URI be hierarchical. This
requirement isn't new -- checkNotNull(targetUri.getPath()) throws today
if the target is opaque.

Also fix sloppy language in javadoc wrt service authority port: it isn't
actually an input to the DNS layer, rather it's copied forward as a
property of our output addresses at the io.grpc.NameResolver layer.
Accept both absolute (e.g. 'dns:///hostname') and rootless
(e.g. 'dns:hostname') paths as specified by
https://github.com/grpc/grpc/blob/master/doc/naming.md and matching the
behavior of grpc core and grpc-go.
@jdcormie jdcormie changed the title Add RFC 3986 support for 'dns' target URIs Add RFC 3986 support to DnsNameResolverProvider Jan 9, 2026
@kannanjgithub kannanjgithub merged commit f65127c into grpc:master Jan 9, 2026
17 checks passed
* target URI, excluding the leading slash {@code '/'}, is treated as the host name and the optional
* port to be resolved by DNS. Example target URIs:
* URI is reserved for the address of alternative DNS server (not implemented yet). The first path
* segment of the hierarchical target URI is interpreted as an RFC 2396 "server-based" authority and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to say the "first path segment" by itself. I would be fine with that if we also say "there must only be one segment." I don't think we want arbitrary stuff added to the end to be ignored dns:/example.com/foo. Allowing dns:example.com is good and fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. My commits all got squashed but this first one was actually just documenting the current behavior, as verified by my new newNameResolver_toleratesTrailingPathSegments() test. It's a surprising (to me) side effect of hostport parsing later, in DnsNameResolver.java, where a new temp nameUri is parsed from the concatenation of "//" with getPath() from the original input target URI. The constructor proceeds with nameUri.getHost() and nameUri.getPort() but ignores nameUri.getPath(), where any additional path segments ended up.

I can certainly change DnsNameResolverProvider#newNameResolver(io.grpc.Uri...) to forbid this but this new restriction will only take effect when the RFC 3984 flag is flipped. I do worry that it could break existing clients and make actually flipping the flag more likely to get rolled back. You could also argue that it's inconsistent with how DnsNameResolverProvider ignores other parts of the target URI it doesn't care about, like user info, query string and fragment . LMK what you think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the extent that RFC 4501 matters, its grammar does not seem to permit additional path segments, user info, fragment, or query params other than CLASS or TYPE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants