diff --git a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java index 3e8ca341c80a2d..0a790408b4f159 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java @@ -808,9 +808,12 @@ private TestAttemptResult runTestAttempt( // Make sure that the test.log exists.Spaw FileSystemUtils.touchFile(fileOutErr.getOutputPath()); } + fileOutErr.close(); // Append any error output to the test.log. This is very rare. + // + // Only write after the error output stream has been closed. Otherwise, Bazel cannot delete + // test.err file on Windows. See https://github.com/bazelbuild/bazel/issues/20741. writeOutFile(fileOutErr.getErrorPath(), fileOutErr.getOutputPath()); - fileOutErr.close(); if (streamed != null) { streamed.close(); }