diff options
author | 2016-04-25 09:44:14 +0000 | |
---|---|---|
committer | 2016-04-25 11:32:04 +0000 | |
commit | b7caf9dd7dfddf30abcbf4ef64cf249944d94073 (patch) | |
tree | 86e66c7cb9ee54d5cd56ea87568f9ebcef6f5a97 | |
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
-rw-r--r-- | src/main/cpp/blaze.cc | 10 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java | 6 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc index 321706a7fb..cbcf4167e9 100644 --- a/src/main/cpp/blaze.cc +++ b/src/main/cpp/blaze.cc @@ -1859,11 +1859,19 @@ GrpcBlazeServer::GrpcBlazeServer() { bool GrpcBlazeServer::Connect() { std::string server_dir = globals->options.output_base + "/server"; std::string port; + std::string ipv4_prefix = "127.0.0.1:"; + std::string ipv6_prefix = "::1:"; if (!ReadFile(server_dir + "/command_port", &port)) { return false; } + // Make sure that we are being directed to localhost + if (port.compare(0, ipv4_prefix.size(), ipv4_prefix) + && port.compare(0, ipv6_prefix.size(), ipv6_prefix)) { + return false; + } + if (!ReadFile(server_dir + "/request_cookie", &request_cookie_)) { return false; } @@ -1873,7 +1881,7 @@ bool GrpcBlazeServer::Connect() { } std::shared_ptr<grpc::Channel> channel(grpc::CreateChannel( - "localhost:" + port, grpc::InsecureChannelCredentials())); + port, grpc::InsecureChannelCredentials())); std::unique_ptr<command_server::CommandServer::Stub> client( command_server::CommandServer::NewStub(channel)); 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); |