diff options
author | Lukacs Berki <lberki@google.com> | 2016-04-25 09:44:14 +0000 |
---|---|---|
committer | Dmitry Lomov <dslomov@google.com> | 2016-04-25 11:32:04 +0000 |
commit | b7caf9dd7dfddf30abcbf4ef64cf249944d94073 (patch) | |
tree | 86e66c7cb9ee54d5cd56ea87568f9ebcef6f5a97 /src/main/java/com | |
parent | 8b388a0739ffaff1487911116f78a4a97004df6e (diff) |
Make the server tell not only the port, but also the address it is listening on.
This is necessary because on Windows/msys2, the Java gRPC server listens only on IPv6 but the C++ client only tries to connect over IPv4, resulting in breakage.
--
MOS_MIGRATED_REVID=120689437
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java b/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java index a5dbbf0ac4..cd6c68d116 100644 --- a/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java +++ b/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java @@ -40,6 +40,7 @@ import io.grpc.stub.StreamObserver; import java.io.IOException; import java.io.OutputStream; import java.lang.reflect.Field; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.nio.channels.ServerSocketChannel; import java.nio.charset.Charset; @@ -224,7 +225,8 @@ public class GrpcServerImpl extends RPCServer implements CommandServerGrpc.Comma @Override public void serve() throws IOException { Preconditions.checkState(!serving); - server = NettyServerBuilder.forAddress(new InetSocketAddress("localhost", port)) + InetAddress loopbackAddress = InetAddress.getLoopbackAddress(); + server = NettyServerBuilder.forAddress(new InetSocketAddress(loopbackAddress, port)) .addService(CommandServerGrpc.bindService(this)) .build(); @@ -235,7 +237,7 @@ public class GrpcServerImpl extends RPCServer implements CommandServerGrpc.Comma port = getActualServerPort(); } - writeServerFile(PORT_FILE, Integer.toString(port)); + writeServerFile(PORT_FILE, loopbackAddress.getHostAddress() + ":" + Integer.toString(port)); writeServerFile(REQUEST_COOKIE_FILE, requestCookie); writeServerFile(RESPONSE_COOKIE_FILE, responseCookie); |