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 #14787.

Closes #14992.

PiperOrigin-RevId: 433205726
  • Loading branch information
coeuvre authored and copybara-github committed Mar 8, 2022
1 parent 426188c commit a73aa12
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 @@ -729,7 +729,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 a73aa12

Please sign in to comment.