aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
index c6892e6479..e33c010263 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
@@ -47,6 +47,7 @@ import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ThreadLocalRandom;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
@@ -130,15 +131,15 @@ public final class LocalSpawnRunner implements SpawnRunner {
}
private static Path createActionTemp(Path execRoot) throws IOException {
- // Use this executor thread's ID as the directory name's suffix.
- // The ID is safe for the following reasons:
- // - being a thread ID, it's guaranteed to be unique among other action executor threads
- // - this thread will only execute one action at a time, so there's no risk of concurrently
- // running actions using the same temp directory.
- // The next action that this thread executes can reuse the temp directory name. The only caveat
- // is, if {@link #start} fails to delete directory after the action is done, the next
- // action will see stale files in its temp directory.
- String idStr = Long.toHexString(Thread.currentThread().getId());
+ String idStr =
+ // Make the name unique among other executor threads.
+ Long.toHexString(Thread.currentThread().getId())
+ + "_"
+ // Make the name unique among other temp directories that this thread has ever created.
+ // On Windows, file and directory deletion is asynchronous, meaning the previous temp
+ // directory name isn't immediately available for the next action that this thread runs.
+ // See https://github.com/bazelbuild/bazel/issues/4035
+ + Long.toHexString(ThreadLocalRandom.current().nextLong());
Path result = execRoot.getRelative("tmp" + idStr);
if (!result.exists() && !result.createDirectory()) {
throw new IOException(String.format("Could not create temp directory '%s'", result));