symat commented on a change in pull request #1254: ZOOKEEPER-2164: Quorum 
members can not rejoin after restart
URL: https://github.com/apache/zookeeper/pull/1254#discussion_r381858077
 
 

 ##########
 File path: 
zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
 ##########
 @@ -266,12 +267,33 @@ public static InitialMessage parse(Long protocolVersion, 
DataInputStream din) th
                 } catch (ArrayIndexOutOfBoundsException e) {
                     throw new InitialMessageException("No port number in: %s", 
addr);
                 }
-                addresses.add(new InetSocketAddress(host_port[0], port));
+                if (!isWildcardAddress(host_port[0])) {
+                    addresses.add(new InetSocketAddress(host_port[0], port));
+                }
             }
 
             return new InitialMessage(sid, addresses);
         }
 
+        /**
+         * Returns true if the specified hostname is a wildcard address,
+         * like 0.0.0.0 for IPv4 or :: for IPv6
+         *
+         * (the function is package-private to be visible for testing)
+         */
+        static boolean isWildcardAddress(final String hostname) {
+            try {
+                return InetAddress.getByName(hostname).isAnyLocalAddress();
+            } catch (UnknownHostException e) {
+                // if we can not resolve, it can not be a wildcard address
+                return false;
 
 Review comment:
   The reasoning here is, that even if in this particular time we can not 
resolve the hostname, it is possible we will be able to do so in the future. So 
I wouldn't throw it away. In case of multi-address, if there are multiple 
addresses provided, then we will start to establish connections in parallel for 
all of them and keeping the one that is alive.
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to