From 61e0f30e387c1dfead3e5d62890ab2a9f3b215a1 Mon Sep 17 00:00:00 2001 From: Nick Hill Date: Tue, 23 Feb 2021 15:58:05 -0800 Subject: [PATCH] stub: Have ClientCalls.ThreadlessExecutor reject Runnables after end of RPC Changes originally proposed as part of #7106. Fixes #3557 --- .../main/java/io/grpc/stub/ClientCalls.java | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/stub/src/main/java/io/grpc/stub/ClientCalls.java b/stub/src/main/java/io/grpc/stub/ClientCalls.java index 0266cb7d9af..e8e29eddcc6 100644 --- a/stub/src/main/java/io/grpc/stub/ClientCalls.java +++ b/stub/src/main/java/io/grpc/stub/ClientCalls.java @@ -39,6 +39,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.concurrent.Future; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.locks.LockSupport; import java.util.logging.Level; import java.util.logging.Logger; @@ -161,6 +162,7 @@ public static RespT blockingUnaryCall( // 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(); } @@ -626,6 +628,9 @@ private Object waitForNext() { // Now wait for onClose() to be called, so interceptors can clean up } } + if (next == this || next instanceof StatusRuntimeException) { + threadless.shutdown(); + } return next; } } finally { @@ -712,7 +717,10 @@ private static final class ThreadlessExecutor extends ConcurrentLinkedQueue