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

Fix race condition and add more logging for null entry error message #21668

Closed
Closed
Changes from 1 commit
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,26 @@ private boolean takeStashedSandboxInternal(
stashExecroot.renameTo(sandboxExecroot);
stash.deleteTree();
if (isTestAction(mnemonic)) {
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() + "\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(stashPathToRunfilesDir.get(stashExecroot));
sandboxExecroot.getRelative(relativeStashedRunfilesDir);
Path currentRunfiles = sandboxExecroot.getRelative(getCurrentRunfilesDir(environment));
currentRunfiles.getParentDirectory().createDirectoryAndParents();
stashedRunfilesDir.renameTo(currentRunfiles);
Expand Down Expand Up @@ -154,11 +173,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is no longer correct.

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