You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by "anmolnar (via GitHub)" <gi...@apache.org> on 2023/06/10 13:58:04 UTC
[GitHub] [zookeeper] anmolnar commented on a diff in pull request #2005: ZOOKEEPER-3860 Avoid reverse DNS lookup for hostname verification when hostnames are provided in the connection url
anmolnar commented on code in PR #2005:
URL: https://github.com/apache/zookeeper/pull/2005#discussion_r1225379186
##########
zookeeper-server/src/main/java/org/apache/zookeeper/common/NetUtils.java:
##########
@@ -27,17 +27,18 @@
*/
public class NetUtils {
+ /**
+ * Prefer using the hostname for formatting, but without requesting reverse DNS lookup.
+ * Fall back to IP address if hostname is unavailable and use [] brackets for IPv6 literal.
+ */
public static String formatInetAddr(InetSocketAddress addr) {
+ String hostString = addr.getHostString();
InetAddress ia = addr.getAddress();
- if (ia == null) {
- return String.format("%s:%s", addr.getHostString(), addr.getPort());
- }
-
- if (ia instanceof Inet6Address) {
- return String.format("[%s]:%s", ia.getHostAddress(), addr.getPort());
+ if (ia instanceof Inet6Address && hostString.contains(":")) {
Review Comment:
Good point, need to check the source, but javadoc says:
> Returns the hostname, or the String form of the address if it doesn't have a hostname (it was created using a literal). This has the benefit of not attempting a reverse lookup.
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/InetSocketAddress.html#getHostString()
How could be null? No hostname and no IP address either in the InetSocketAddress. What sort of socket address does it represent in such case?
I think we're good without the null check, but I'll take a look at the source.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org