From f9b6ac03c6c6672edd8e1493b56925e76a1c409b Mon Sep 17 00:00:00 2001 From: Viktor Lofgren Date: Sun, 18 Feb 2024 08:45:35 +0100 Subject: [PATCH] (api) Clean up incorrect error handling in GrpcChannelPool --- .../java/nu/marginalia/client/grpc/GrpcChannelPool.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/code/common/service-client/src/main/java/nu/marginalia/client/grpc/GrpcChannelPool.java b/code/common/service-client/src/main/java/nu/marginalia/client/grpc/GrpcChannelPool.java index d2508dfa..6c23a841 100644 --- a/code/common/service-client/src/main/java/nu/marginalia/client/grpc/GrpcChannelPool.java +++ b/code/common/service-client/src/main/java/nu/marginalia/client/grpc/GrpcChannelPool.java @@ -44,9 +44,16 @@ public abstract class GrpcChannelPool { } private ManagedChannel refreshChannel(ServiceAndNode serviceAndNode, ManagedChannel old) { - if (old == null || old.getState(true) != SHUTDOWN) { + if (old == null) + return createChannel(serviceAndNode); + + // If the channel is in SHUTDOWN state, we need to create a new one + // (shouldn't really happen in practice, but it's a good idea to be safe) + if (old.getState(true) == SHUTDOWN) { + old.shutdown(); return createChannel(serviceAndNode); } + return old; }