Skip to content

Commit 61e84d6

Browse files
committed
fix: add isAvailable check in getInvoker to prevent idle eviction race condition
1 parent 953a3c6 commit 61e84d6

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

trpc-core/src/main/java/com/tencent/trpc/core/cluster/def/DefClusterInvoker.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ protected CompletionStage<Response> doInvoke(Request request, CompletionStage<Se
7272
protected ConsumerInvokerProxy<T> getInvoker(ServiceInstance instance) {
7373
String key = toUniqKey(instance);
7474
ConsumerInvokerProxy<T> result = invokerCache.get(key);
75-
return Optional.ofNullable(result).orElseGet(() -> createInvoker(instance));
75+
// Check availability on fast path to prevent using an invoker whose underlying
76+
// RpcClient is being closed by the idle scanner (scanUnusedClient).
77+
// Without this check, a race condition exists between the scheduler closing the
78+
// client and the closeFuture callback removing the invoker from cache.
79+
if (result != null && result.isAvailable()) {
80+
return result;
81+
}
82+
return createInvoker(instance);
7683
}
7784

7885
@SuppressWarnings("rawtypes")

0 commit comments

Comments
 (0)