aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Changming Sun <chasun@microsoft.com>2017-11-20 05:34:25 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-11-20 05:35:49 -0800
commitd0bf589f2716b3d139c210930371a684c6e158eb (patch)
treec16cac088ce5923b7210de9c14c17932beec0150 /src/main
parentc8be465869fbcfaa00b75d241c67279324976e0b (diff)
Add a random number to action temp dir
Fix for #4035 @laszlocsomor Closes #4110. PiperOrigin-RevId: 176346381
Diffstat (limited to 'src/main')
-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));