How to sever TCP connection server-side? (grpc-java)

33 views
Skip to first unread message

pepe...@gmail.com

unread,
Jun 1, 2020, 8:59:47 PM6/1/20
to grpc.io
Hello!

I'm accepting bidirectional streaming gRPC connections (grpc-java, Netty) on a set of servers and are hoping to use DNS to route traffic. I'd like to be able to update a DNS record to get a client to connect to a different server as a method of load shifting. As the connections are long-lived, I'm finding that clients need to be prompted to disconnect to refresh their DNS entry and connect to the new server. I've tried several methods (returning an error response to the observer in a stream method, closing the call in the listener) but it looks like I'm able to close the channel, but never the underlying TCP connection, and so the DNS refresh never happens. 

Is there a way to close a connection from the server in grpc-java? Restarting the server prompts the client to refresh, as does setting a maximum connection age, but I'd like to avoid the overhead of closing connections on a cadence.

Thanks!

Jihun Cho

unread,
Jun 2, 2020, 12:46:37 PM6/2/20
to pepe...@gmail.com, grpc.io
A lot of things are going on here. TCP connection is channel level if you want to teardown the connection, you need to close the channel. shutdown and shutdownNow does not teardown the connection immediately, did you wait until termination?

You may consider using NettyServerBuilder#maxConnectionAge and NettyServerBuilder#maxConnectionAgeGrace on the server side to rebalance connections. If this doesn't solve the problem, you may want to implement your own load balancer which isn't bad but it is not a simple configuration.


--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/dbd20923-dc3d-4271-a524-6d975672ff8c%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages