Skip to content

Commit

Permalink
Fix ProxyTunnel to always use the IP-address instead of the localhost (
Browse files Browse the repository at this point in the history
…#1563)

Motivation:

ProxyTunnel was returning the `localhost` hostname instead of the IP-address, which in some configurations
where the IPv4 is preferred but the DNS resolves in both IPv4 and IPv6 for the loopback hostname,
cause connectivity issues.

Modifications:

Modified the ProxyTunnel to always return the IP-address for the clients to connect to.

Result:

More stable test.
  • Loading branch information
tkountis authored May 14, 2021
1 parent 4e128eb commit fecc3d3
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2020 Apple Inc. and the ServiceTalk project authors
* Copyright © 2020-2021 Apple Inc. and the ServiceTalk project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -61,6 +61,7 @@ public void close() throws Exception {

HostAndPort startProxy() throws IOException {
serverSocket = new ServerSocket(0, 50, getLoopbackAddress());
final InetSocketAddress serverSocketAddress = (InetSocketAddress) serverSocket.getLocalSocketAddress();
executor.submit(() -> {
while (!executor.isShutdown()) {
final Socket socket = serverSocket.accept();
Expand All @@ -86,7 +87,8 @@ HostAndPort startProxy() throws IOException {
}
return null;
});
return HostAndPort.of((InetSocketAddress) serverSocket.getLocalSocketAddress());

return HostAndPort.of(serverSocketAddress.getAddress().getHostAddress(), serverSocketAddress.getPort());
}

void badResponseProxy() {
Expand Down

0 comments on commit fecc3d3

Please sign in to comment.