grpc-java - how to close a channel that has an interceptor

30 views
Skip to first unread message

Cosmin Lehene

unread,
Aug 4, 2020, 1:13:01 AM8/4/20
to grpc.io
ManagedChannel has shutdown()
However, our code adds an interceptor with ClientInterceptors.intercept(..) which returns a Channel, which doesn't have shutdown. 

It seems we're doing it wrong. But what's the right way to have a cloasable client with an interceptor?

Thank you!

zda...@google.com

unread,
Aug 5, 2020, 7:24:29 PM8/5/20
to grpc.io
There is a reason for the API design of ClientInterceptors.intercept(..) returning a Channel rather than ManagedChannel: The original managed channel is the single entity that is responsible for the life-cycle of the channel. If you are not the owner of the original ManagedChannel instance, you are not responsible and should not shut it down. If you are owner of the original ManageChannel, you are responsible to shut it down, and you need pass the reference to the original ManagedChannel to the caller of shutdown().

That might be very inconvenient in some cases, but that's how it is supposed to work.

Reply all
Reply to author
Forward
0 new messages