Skip to content

Commit

Permalink
Fix a race when reading FileOutErr
Browse files Browse the repository at this point in the history
  • Loading branch information
coeuvre committed Jul 28, 2021
1 parent a36ba3b commit 5fd6c3b
Showing 1 changed file with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -741,39 +741,39 @@ public void uploadOutputs(RemoteAction action)
checkState(!shutdown.get(), "shutdown");
checkNotNull(remoteCache, "remoteCache can't be null");

Collection<Path> outputFiles =
action.spawn.getOutputFiles().stream()
.map((inp) -> execRoot.getRelative(inp.getExecPath()))
.collect(ImmutableList.toImmutableList());

ActionResult.Builder result = ActionResult.newBuilder();
result.setExitCode(0);

UploadManifest manifest =
new UploadManifest(
digestUtil,
remotePathResolver,
result,
remoteOptions.incompatibleRemoteSymlinks,
remoteOptions.allowSymlinkUpload);
manifest.addFiles(outputFiles);
manifest.setStdoutStderr(action.spawnExecutionContext.getFileOutErr());
manifest.addAction(action.actionKey, action.action, action.command);
if (manifest.getStderrDigest() != null) {
result.setStderrDigest(manifest.getStderrDigest());
}
if (manifest.getStdoutDigest() != null) {
result.setStdoutDigest(manifest.getStdoutDigest());
}

CountDownLatch uploadStartedLatch = new CountDownLatch(1);

Completable uploads = Completable.using(
remoteCache::retain,
remoteCache -> {
uploadStartedLatch.countDown();

Collection<Path> outputFiles =
action.spawn.getOutputFiles().stream()
.map((inp) -> execRoot.getRelative(inp.getExecPath()))
.collect(ImmutableList.toImmutableList());

ActionResult.Builder result = ActionResult.newBuilder();
result.setExitCode(0);

UploadManifest manifest =
new UploadManifest(
digestUtil,
remotePathResolver,
result,
remoteOptions.incompatibleRemoteSymlinks,
remoteOptions.allowSymlinkUpload);
manifest.addFiles(outputFiles);
manifest.setStdoutStderr(action.spawnExecutionContext.getFileOutErr());
manifest.addAction(action.actionKey, action.action, action.command);
if (manifest.getStderrDigest() != null) {
result.setStderrDigest(manifest.getStderrDigest());
}
if (manifest.getStdoutDigest() != null) {
result.setStdoutDigest(manifest.getStdoutDigest());
}
remoteCache::retain,
remoteCache -> {
uploadStartedLatch.countDown();

return Completable.concatArray(
return Completable.concatArray(
uploadOutputs(remoteCache, action, manifest),
uploadActionResult(remoteCache, action, result.build()));
},
Expand Down

0 comments on commit 5fd6c3b

Please sign in to comment.