Skip to content

Commit

Permalink
Remote: Fix crashes with InterruptedException when using http cache. (b…
Browse files Browse the repository at this point in the history
…azelbuild#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]>
  • Loading branch information
brentleyjones and coeuvre authored Mar 8, 2022
1 parent 7937dd1 commit 6cd6a27
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 6cd6a27

Please sign in to comment.