Skip to content

Commit

Permalink
Wait for background tasks finished before releasing remoteCache.
Browse files Browse the repository at this point in the history
So that the last task won't try to shutdown the remoteCache, otherwise, might cause deadlocks.

Fixes #21568.

PiperOrigin-RevId: 635746896
Change-Id: Ic321216dd0bda05ef1ad18367c8ebbcd1a1d272c
  • Loading branch information
coeuvre authored and copybara-github committed May 21, 2024
1 parent 01a90d6 commit a804fb1
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1596,15 +1596,19 @@ public void shutdown() {
}

if (remoteCache != null) {
remoteCache.release();

try {
backgroundTaskPhaser.awaitAdvanceInterruptibly(backgroundTaskPhaser.arrive());
} catch (InterruptedException e) {
buildInterrupted.set(true);
remoteCache.shutdownNow();
Thread.currentThread().interrupt();
}

// Only release the remoteCache once all background tasks have been finished. Otherwise, the
// last task might try to close the remoteCache inside the callback of network response which
// might cause deadlocks.
// See https://github.com/bazelbuild/bazel/issues/21568.
remoteCache.release();
}

if (remoteExecutor != null) {
Expand Down

0 comments on commit a804fb1

Please sign in to comment.