Github user eribeiro commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/173#discussion_r101845264
--- 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 --
My main problem with this PR is that call to `isReachable(timeout)` for two
reasons:
1) the most important one: `isReachable(timeout)` seems unreliable so there
are plenty cases where it returns false even tough the node is reachable or
vice-versa! https://bugs.openjdk.java.net/browse/JDK-8159410 (google
"InetAddress.isReachable not working" or "InetAddress.isReachable unreliable"
to see further cases).
2) This timeout can add an arbitrary delay until a reachable node can be
tested.
IDK what a good compromise would be for both points above (leaving as it is
today could work, so no problem, even tough I am a bit concerned), but maybe we
could use a solution similar to ZOOKEEPER-2184 and return the next address in
the array (using `next = ++next % addresses.length` to prevent out of bound
exceptions).
---
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.
---