From 574fbb43274546e40827ef4232a2bebba7ad57af Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Fri, 1 Apr 2022 08:49:34 -0700 Subject: [PATCH] stub: Shutdown ThreadlessExecutor only if onClose() is called (#9041) It is only safe to shutdown the executor if onClose() is called. Normal RPC completions (both success and failure) will see the future complete, so this only avoids shutting down in stranger cases like an interceptor throwing an exception. --- stub/src/main/java/io/grpc/stub/ClientCalls.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stub/src/main/java/io/grpc/stub/ClientCalls.java b/stub/src/main/java/io/grpc/stub/ClientCalls.java index 980e7399a8..4fac94bfae 100644 --- a/stub/src/main/java/io/grpc/stub/ClientCalls.java +++ b/stub/src/main/java/io/grpc/stub/ClientCalls.java @@ -161,6 +161,7 @@ public final class ClientCalls { // Now wait for onClose() to be called, so interceptors can clean up } } + executor.shutdown(); return getUnchecked(responseFuture); } catch (RuntimeException e) { // Something very bad happened. All bets are off; it may be dangerous to wait for onClose(). @@ -169,7 +170,6 @@ public final class ClientCalls { // Something very bad happened. All bets are off; it may be dangerous to wait for onClose(). throw cancelThrow(call, e); } finally { - executor.shutdown(); if (interrupt) { Thread.currentThread().interrupt(); }