Skip to content

Commit

Permalink
ZOOKEEPER-2664: ClientPortBindTest#testBindByAddress may fail due to …
Browse files Browse the repository at this point in the history
…"No such device" exception

The following stack trace was observed intermittently:
```
Stacktrace

java.net.SocketException: No such device
	at java.net.NetworkInterface.isLoopback0(Native Method)
	at java.net.NetworkInterface.isLoopback(NetworkInterface.java:390)
	at org.apache.zookeeper.test.ClientPortBindTest.testBindByAddress(ClientPortBindTest.java:61)
	at org.apache.zookeeper.JUnit4ZKTestRunner$LoggedInvokeMethod.evaluate(JUnit4ZKTestRunner.java:52)
Standard Output
```
Proposed fix is to catch exception from isLoopback() call and skip the test in that case.

Author: tedyu <yuzhihong@gmail.com>

Reviewers: Edward Ribeiro <edward.ribeiro@gmail.com>, Michael Han <hanm@apache.org>

Closes apache#149 from tedyu/master
  • Loading branch information
tedyu authored and RokLenarcic committed Sep 3, 2022
1 parent 0838dcf commit 0d28f83
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/java/test/org/apache/zookeeper/test/ClientPortBindTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

import org.slf4j.Logger;
Expand Down Expand Up @@ -51,15 +52,19 @@ public void testBindByAddress() throws Exception {
// if we have a loopback and it has an address use it
while(intfs.hasMoreElements()) {
NetworkInterface i = intfs.nextElement();
if (i.isLoopback()) {
Enumeration<InetAddress> addrs = i.getInetAddresses();
while (addrs.hasMoreElements()) {
try {
if (i.isLoopback()) {
Enumeration<InetAddress> addrs = i.getInetAddresses();
while (addrs.hasMoreElements()) {
InetAddress a = addrs.nextElement();
if(a.isLoopbackAddress()) {
bindAddress = a.getHostAddress();
break;
bindAddress = a.getHostAddress();
break;
}
}
}
} catch (SocketException se) {
LOG.warn("Couldn't find loopback interface: " + se.getMessage());
}
}
if (bindAddress == null) {
Expand Down

0 comments on commit 0d28f83

Please sign in to comment.