Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions flink-core/src/main/java/org/apache/flink/util/NetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ public static String unresolvedHostToNormalizedString(String host) {
host = InetAddress.getLoopbackAddress().getHostAddress();
} else {
host = host.trim().toLowerCase();
if (host.startsWith("[") && host.endsWith("]")) {
String address = host.substring(1, host.length() - 1);
if (IPAddressUtil.isIPv6LiteralAddress(address)) {
host = address;
}
}
}

// normalize and valid address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ public void testFormatAddress() throws UnknownHostException {
int port = 42;
Assert.assertEquals("[2001:db8:85a3::8a2e:370:7334]:" + port, NetUtils.unresolvedHostAndPortToNormalizedString(host, port));
}
{
// [IPv6]
String host = "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]";
int port = 42;
Assert.assertEquals("[2001:db8:85a3::8a2e:370:7334]:" + port, NetUtils.unresolvedHostAndPortToNormalizedString(host, port));
}
{
// Hostnames
String host = "somerandomhostname";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,8 @@ object AkkaUtils {
| remote {
| netty {
| tcp {
| hostname = $effectiveHostname
| bind-hostname = $bindAddress
| hostname = "$effectiveHostname"
| bind-hostname = "$bindAddress"
| }
| }
| }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,15 @@ class AkkaUtilsTest
akkaConfig.getInt("akka.actor.default-dispatcher.thread-pool-executor.core-pool-size-max")
.should(equal(maxThreads))
}

test("getAkkaConfig should work with ipv6 addresses") {
val ipv6AddressString = "2001:db8:10:11:12:ff00:42:8329"
val configuration = new Configuration()
val port = 1234

val akkaConfig = AkkaUtils.getAkkaConfig(configuration, ipv6AddressString, port)

akkaConfig.getString("akka.remote.netty.tcp.hostname") should
equal(NetUtils.unresolvedHostToNormalizedString(ipv6AddressString))
}
}