Skip to content

Commit 27443b8

Browse files
committed
clickhouse-http-client: fix getLocalhost to return the first address
As written the break doesn't apply to the outer loop so it's not the first address that's returned, rather the last one.
1 parent 28f8baf commit 27443b8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

clickhouse-http-client/src/main/java/com/clickhouse/client/http/ClickHouseHttpClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ private static HostNameAndAddress getLocalHost() {
4848
try {
4949
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
5050

51+
outer:
5152
for (NetworkInterface ni : Collections.list(networkInterfaces)) {
5253
Enumeration<InetAddress> inetAddresses = ni.getInetAddresses();
5354
for (InetAddress ia : Collections.list(inetAddresses)) {
5455
// We just use the first non-loopback address
5556
if (!ia.isLoopbackAddress() && !ia.isLinkLocalAddress()) {
5657
hostNameAndAddress.address = ia.getHostAddress();
5758
hostNameAndAddress.hostName = ia.getCanonicalHostName();
58-
break;
59+
break outer;
5960
}
6061
}
6162
}

0 commit comments

Comments
 (0)