Skip to content

Commit

Permalink
Suppress interrupted status during pool closure
Browse files Browse the repository at this point in the history
awaitTermination will throw InterruptedException if the interrupted
status is set initially when it is called, even if no wait is required.
Pool closure should not respect active interrupted status when shutting
down and awaiting termination as a result of its call from
executionPhaseEnding, which will occur during abnormal exits from
ExecutionTool. Ignore this status initially and restore the flag upon
exit of the factory close. An external interrupt which occurs during the
awaitTermination will still trigger an InterruptedException, as
expected.

Fixes #13512

Closes #13521.

PiperOrigin-RevId: 377006347
  • Loading branch information
werkt authored and katre committed Jul 12, 2021
1 parent e9de54a commit f54ce3c
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> call(

@Override
public void close() throws IOException {
// Clear interrupted status to prevent failure to await, indicated with #13512
boolean wasInterrupted = Thread.interrupted();
// There is a bug (b/183340374) in gRPC that client doesn't try to close connections with
// shutdown() if the channel received GO_AWAY frames. Using shutdownNow() here as a
// workaround.
channel.shutdownNow();
try {
channel.shutdownNow();
channel.awaitTermination(Integer.MAX_VALUE, SECONDS);
} catch (InterruptedException e) {
throw new IOException(e.getMessage(), e);
} finally {
if (wasInterrupted) {
Thread.currentThread().interrupt();
}
}
}

Expand Down

0 comments on commit f54ce3c

Please sign in to comment.