Skip to content

Commit

Permalink
Check if treeDeleter is actually async before casting it. Fixes baz…
Browse files Browse the repository at this point in the history
…elbuild#13240.

This code assumed that `registerSpawnStrategies` would be always be called before `afterCommand`, but that's not the case if the build was interrupted or failed before the execution phase.

RELNOTES: None.
PiperOrigin-RevId: 379937925
  • Loading branch information
larsrc-google authored and copybara-github committed Jun 17, 2021
1 parent 2611ec0 commit 2c3cff5
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,17 @@ public void afterCommand() {

SandboxOptions options = env.getOptions().getOptions(SandboxOptions.class);
int asyncTreeDeleteThreads = options != null ? options.asyncTreeDeleteIdleThreads : 0;
if (treeDeleter != null && asyncTreeDeleteThreads > 0) {
// If asynchronous deletions were requested, they may still be ongoing so let them be: trying
// to delete the base tree synchronously could fail as we can race with those other deletions,
// and scheduling an asynchronous deletion could race with future builds.
AsynchronousTreeDeleter treeDeleter =
(AsynchronousTreeDeleter) checkNotNull(this.treeDeleter);

// If asynchronous deletions were requested, they may still be ongoing so let them be: trying
// to delete the base tree synchronously could fail as we can race with those other deletions,
// and scheduling an asynchronous deletion could race with future builds.
if (asyncTreeDeleteThreads > 0 && treeDeleter instanceof AsynchronousTreeDeleter) {
AsynchronousTreeDeleter treeDeleter = (AsynchronousTreeDeleter) this.treeDeleter;
treeDeleter.setThreads(asyncTreeDeleteThreads);
}
// `treeDeleter` might not be an AsynchronousTreeDeleter if the user changed the option but
// then interrupted the build before the start of the execution phase. But that's OK, there
// will be nothing new to delete. See #13240.

if (shouldCleanupSandboxBase) {
try {
Expand Down

0 comments on commit 2c3cff5

Please sign in to comment.