in ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcUtil.java [218:246]
static void shutdownManagedChannel(ManagedChannel managedChannel) {
// Close the gRPC managed-channel if not shut down already.
if (!managedChannel.isShutdown()) {
try {
managedChannel.shutdown();
if (!managedChannel.awaitTermination(3, TimeUnit.SECONDS)) {
LOG.warn("Timed out gracefully shutting down connection: {}. ", managedChannel);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
LOG.error("Unexpected exception while waiting for channel termination", e);
}
}
// Forceful shut down if still not terminated.
if (!managedChannel.isTerminated()) {
try {
managedChannel.shutdownNow();
if (!managedChannel.awaitTermination(2, TimeUnit.SECONDS)) {
LOG.warn("Timed out forcefully shutting down connection: {}. ", managedChannel);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
LOG.error("Unexpected exception while waiting for channel termination", e);
}
}
}