-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use ServerBootstrap to start then start grpc server with same port don't throw BindException: Address already in use #3824
Comments
So you expected to see an error, and there wasn't one? From the code, it looks like that can happen. If the thread you start hasn't started yet, the gRPC server can win the race. Actually I would expect the gRPC to win in this case. |
@carl-mastrangelo |
I reliably get an exception. I modified the interop server with: diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java
index 48dd37db..3ec70777 100644
--- a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java
+++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java
@@ -23,6 +23,11 @@ import io.grpc.ServerInterceptors;
import io.grpc.internal.testing.TestUtils;
import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NettyServerBuilder;
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.ssl.SslContext;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -44,6 +49,14 @@ public class TestServiceServer {
+ "*.test.google.fr and our test CA. For the Java test client binary, use:\n"
+ "--server_host_override=foo.test.google.fr --use_test_ca=true\n");
}
+ new ServerBootstrap()
+ .group(new NioEventLoopGroup(1), new NioEventLoopGroup(1))
+ .channel(NioServerSocketChannel.class)
+ .childHandler(new ChannelInitializer<SocketChannel>() {
+ @Override public void initChannel(SocketChannel ch) {}
+ })
+ .bind("127.0.0.1", 8080)
+ .sync();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
|
it dosen't make sence...
|
@SeriousMa, does that last code snippet fail with |
@ejona86 nothing happend.. |
@SeriousMa, I just re-tested with grpc-java 1.7 with the same behavior. I'm running Linux with Java 1.8.0_121. Could there be something about your environment that is different? |
@ejona86 hi |
@carl-mastrangelo, could you run the same test I did in #3824 (comment) on your Mac and see if you see the expected bind failure? |
@ejona86 I applied the diff and ran the binary. I got no exception when running. EDIT: which makes sense lsof says:
|
@SeriousMa, it seems this is just OS X's behavior being different than Linux. Listen on 0.0.0.0 instead of 127.0.0.1 and it should likely fail on OS X as you expected. |
Ran into an interesting scenario today. grpc java 1.7, Mac OS but reason to suspect Linux as well. It seems like a grpc server will silently ignore being unable to bind to the IPV4 address for some port if it is able to bind to the IPV6 address. This was a problem for us because we had a server port conflict in a container but our grpc service appeared to start, although it was unreachable on the IPV4 address. We would have liked the grpc server to fail to start. Works:
Fails on step #2 "nc: Address already in use":
Fails on step #2 "IOException: Failed to bind"
|
@pnambiarsf, on my Linux machine the first one fails ( |
What version of gRPC are you using?
1.7.0
What did you expect to see?
throw BindException: Address already in use
The text was updated successfully, but these errors were encountered: