Skip to content

Commit 2c3cff5

Browse files
larsrc-googlecopybara-github
authored andcommitted
Check if treeDeleter is actually async before casting it. Fixes #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
1 parent 2611ec0 commit 2c3cff5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,17 @@ public void afterCommand() {
607607

608608
SandboxOptions options = env.getOptions().getOptions(SandboxOptions.class);
609609
int asyncTreeDeleteThreads = options != null ? options.asyncTreeDeleteIdleThreads : 0;
610-
if (treeDeleter != null && asyncTreeDeleteThreads > 0) {
611-
// If asynchronous deletions were requested, they may still be ongoing so let them be: trying
612-
// to delete the base tree synchronously could fail as we can race with those other deletions,
613-
// and scheduling an asynchronous deletion could race with future builds.
614-
AsynchronousTreeDeleter treeDeleter =
615-
(AsynchronousTreeDeleter) checkNotNull(this.treeDeleter);
610+
611+
// If asynchronous deletions were requested, they may still be ongoing so let them be: trying
612+
// to delete the base tree synchronously could fail as we can race with those other deletions,
613+
// and scheduling an asynchronous deletion could race with future builds.
614+
if (asyncTreeDeleteThreads > 0 && treeDeleter instanceof AsynchronousTreeDeleter) {
615+
AsynchronousTreeDeleter treeDeleter = (AsynchronousTreeDeleter) this.treeDeleter;
616616
treeDeleter.setThreads(asyncTreeDeleteThreads);
617617
}
618+
// `treeDeleter` might not be an AsynchronousTreeDeleter if the user changed the option but
619+
// then interrupted the build before the start of the execution phase. But that's OK, there
620+
// will be nothing new to delete. See #13240.
618621

619622
if (shouldCleanupSandboxBase) {
620623
try {

0 commit comments

Comments
 (0)