Skip to content

Commit 6cd6a27

Browse files
Remote: Fix crashes with InterruptedException when using http cache. (bazelbuild#14999)
Also cancels tasks submitted during `afterCommand` if interrupted. Fixes bazelbuild#14787. Closes bazelbuild#14992. PiperOrigin-RevId: 433205726 (cherry picked from commit a73aa12) Co-authored-by: Chi Wang <[email protected]>
1 parent 7937dd1 commit 6cd6a27

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/main/java/com/google/devtools/build/lib/remote/http/HttpCacheClient.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,23 @@ public void close() {
733733
}
734734

735735
isClosed = true;
736-
channelPool.close();
736+
737+
// Clear interrupted status to prevent failure to close, indicated with #14787
738+
boolean wasInterrupted = Thread.interrupted();
739+
try {
740+
channelPool.close();
741+
} catch (RuntimeException e) {
742+
if (e.getCause() instanceof InterruptedException) {
743+
Thread.currentThread().interrupt();
744+
} else {
745+
throw e;
746+
}
747+
} finally {
748+
if (wasInterrupted) {
749+
Thread.currentThread().interrupt();
750+
}
751+
}
752+
737753
eventLoop.shutdownGracefully();
738754
}
739755
}

src/main/java/com/google/devtools/build/lib/runtime/BlockWaitingModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void afterCommand() throws AbruptExitException {
5151
try {
5252
executorService.awaitTermination(Long.MAX_VALUE, SECONDS);
5353
} catch (InterruptedException e) {
54+
executorService.shutdownNow();
5455
Thread.currentThread().interrupt();
5556
}
5657

0 commit comments

Comments
 (0)