Imagine you are 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 you create a gRPC channel, you 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");
}
If you still have any questions, feel free to ask me in the comments under this article, or write me on promark33@gmail.com.