diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java index 6bb495b895ba2c..074bf39773418d 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java @@ -932,6 +932,18 @@ public StructImpl downloadAndExtract( env.getListener(), envVariables, getIdentifyingStringForLogging()); + // Ensure that the download is cancelled if the repo rule is restarted as it runs in its own + // executor. + PendingDownload pendingTask = + new PendingDownload( + /* executable= */ false, + allowFail, + outputPath, + checksum, + checksumValidation, + pendingDownload, + thread.getCallerLocation()); + registerAsyncTask(pendingTask); downloadedPath = downloadManager.finalizeDownload(pendingDownload); } catch (IOException e) { env.getListener().post(w);