Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.1.1] Fix race condition and add more logging for null entry error message #21692

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.devtools.build.lib.sandbox;

import com.google.common.base.Preconditions;
import com.google.common.flogger.GoogleLogger;
import com.google.devtools.build.lib.exec.TreeDeleter;
import com.google.devtools.build.lib.sandbox.SandboxHelpers.SandboxOutputs;
Expand Down Expand Up @@ -95,8 +96,29 @@ private boolean takeStashedSandboxInternal(
stashExecroot.renameTo(sandboxExecroot);
stash.deleteTree();
if (isTestAction(mnemonic)) {
Path stashedRunfilesDir =
sandboxExecroot.getRelative(stashPathToRunfilesDir.get(stashExecroot));
String relativeStashedRunfilesDir = stashPathToRunfilesDir.get(stashExecroot);
if (relativeStashedRunfilesDir == null) {
StringBuilder errorMessageBuilder = new StringBuilder();
errorMessageBuilder.append(
String.format("Current stashExecroot:%s\n", stashExecroot));
errorMessageBuilder.append("Stashes:\n");
for (Path path : stashes) {
errorMessageBuilder.append(path.getPathString()).append("\n");
}
errorMessageBuilder.append("Environment:\n");
for (var entry : environment.entrySet()) {
errorMessageBuilder.append(
String.format("%s : %s\n", entry.getKey(), entry.getValue()));
}
errorMessageBuilder.append("Entries runfiles map:\n");
for (var entry : stashPathToRunfilesDir.entrySet()) {
errorMessageBuilder.append(
String.format("%s : %s\n", entry.getKey(), entry.getValue()));
}
Preconditions.checkNotNull(
relativeStashedRunfilesDir, errorMessageBuilder.toString());
}
Path stashedRunfilesDir = sandboxExecroot.getRelative(relativeStashedRunfilesDir);
Path currentRunfiles = sandboxExecroot.getRelative(getCurrentRunfilesDir(environment));
currentRunfiles.getParentDirectory().createDirectoryAndParents();
stashedRunfilesDir.renameTo(currentRunfiles);
Expand Down Expand Up @@ -154,11 +176,11 @@ private void stashSandboxInternal(
path.getRelative("execroot/" + environment.get("TEST_WORKSPACE") + "/_tmp"));
}
}
path.getChild("execroot").renameTo(stashPathExecroot);
if (isTestAction(mnemonic)) {
// We only do this after the rename operation has succeeded
// We do this before the rename operation to avoid a race condition.
stashPathToRunfilesDir.put(stashPathExecroot, getCurrentRunfilesDir(environment));
}
path.getChild("execroot").renameTo(stashPathExecroot);
} catch (IOException e) {
// Since stash names are unique, this IOException indicates some other problem with stashing,
// so we turn it off.
Expand Down
Loading