Github user hanm commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/173#discussion_r116099795
--- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
---
@@ -181,6 +197,33 @@ public void recreateSocketAddresses() {
}
}
+ /**
+ * Resolve the hostname to IP addresses, and find one reachable
address.
+ *
+ * @param hostname the name of the host
+ * @param timeout the time, in millseconds, before {@link
InetAddress#isReachable}
+ * aborts
+ * @return a reachable IP address. If no such IP address can be
found,
+ * just return the first IP address of the hostname.
+ *
+ * @exception UnknownHostException
+ */
+ public InetAddress getReachableAddress(String hostname, int
timeout)
+ throws UnknownHostException {
+ InetAddress[] addresses = InetAddress.getAllByName(hostname);
+ for (InetAddress a : addresses) {
+ try {
+ if (a.isReachable(timeout)) {
--- End diff --
I think this is a valid concern. On top of this, I think we should make
sure user can resort to old behavior if needed. With this patch the
`isReachable` will be called in any case, regardless of the property
'zookeeper.ipReachableTimeout' is defined or not. How about something like this:
if (zookeeper.ipReachableTimeout is not defined) {
address = InetAddress.getByName(this.hostname);
} else {
address = getReachableAddress(this.hostname, ipReachableTimeout);
}
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---