Skip to content

Commit

Permalink
Remote: Fix crashes with InterruptedException when using http cache.
Browse files Browse the repository at this point in the history
Also cancels tasks submitted during `afterCommand` if interrupted.

Fixes bazelbuild#14787.

Closes bazelbuild#14992.

PiperOrigin-RevId: 433205726
(cherry picked from commit a73aa12)
  • Loading branch information
coeuvre authored and brentleyjones committed Mar 8, 2022
1 parent 7937dd1 commit aa161e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,23 @@ public void close() {
}

isClosed = true;
channelPool.close();

// Clear interrupted status to prevent failure to close, indicated with #14787
boolean wasInterrupted = Thread.interrupted();
try {
channelPool.close();
} catch (RuntimeException e) {
if (e.getCause() instanceof InterruptedException) {
Thread.currentThread().interrupt();
} else {
throw e;
}
} finally {
if (wasInterrupted) {
Thread.currentThread().interrupt();
}
}

eventLoop.shutdownGracefully();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void afterCommand() throws AbruptExitException {
try {
executorService.awaitTermination(Long.MAX_VALUE, SECONDS);
} catch (InterruptedException e) {
executorService.shutdownNow();
Thread.currentThread().interrupt();
}

Expand Down

0 comments on commit aa161e1

Please sign in to comment.