gRPC channel shutdown error


What's inside this article ⌄
  • GRPC channel shutdown error
  • GRPC channel not shutdown properly
  • How to shutdown gRPC channel
  • GRPC channel cleanup issue

Imagine you we faced with an error like this:

io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference cleanQueue
SEVERE: ~~~ Channel ManagedChannelImpl{logId=*, target=*} was not shutdown properly!!! ~~~
Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true.
java.lang.RuntimeException: ManagedChannel allocation site
at io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.(ManagedChannelOrphanWrapper.java:94)
at io.grpc.internal.ManagedChannelOrphanWrapper.(ManagedChannelOrphanWrapper.java:52)
at io.grpc.internal.ManagedChannelOrphanWrapper.(ManagedChannelOrphanWrapper.java:43)

The point is that if we create a gRPC channel, we must close it after use. Let’s say you’ve already made a channel like this:

ManagedChannel channel = NettyChannelBuilder.forAddress(host, port)
    .usePlaintext()
    .build();

After use, it will need to be closed. It is important to wait until it closes; awaitTermination() is used for this:

channel.shutdown();
try {
    channel.awaitTermination(5000, TimeUnit.MILLISECONDS);
} catch (InterruptedException ex) {
    log.error("gRPC channel shutdown interrupted");
}