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 bazelbuild#13512

Closes bazelbuild#13521.

PiperOrigin-RevId: 377006347
  • Loading branch information
werkt authored and katre committed Jul 13, 2021
1 parent 66ac5e5 commit f538749
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 f538749

Please sign in to comment.