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 bazel-io committed May 22, 2024
1 parent 87b0a1f commit bffb6d8
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1597,15 +1597,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 bffb6d8

Please sign in to comment.