Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a race condition in Bazel's Windows process management.
(Second version of this PR that fixes the issues from the last time and refactors the code a bit to make it easier to understand and maintain.) While we did correctly terminate the job object of a process when calling Subprocess.destroy and we did correctly wait for the process itself to exit in Subprocess.waitFor, we didn't wait for its children to exit. This is usually not a big problem, except when they keep open some file handles to files that Bazel immediately tris to delete after killing / waiting for the main process, in which case the files might still be in use. This is the reason why we're seeing errors like this on CI: https://buildkite.com/bazel/bazel-bazel/builds/5774#27afa2c9-9ff1-4224-9df7-ba0253e7e317/193-303 "Caught I/O exception: Cannot delete path (something below $TEST_TMPDIR): Access is denied." This CL modifies the behavior to explicitly terminate the job object in Subprocess.waitFor when the main process has exited and then wait for all transitive subprocesses to exit, before continuing. Due to some interesting semantics, one cannot simply use WaitForSingleObject on the Job handle, instead one has to use an IoCompletionPort that gets a signal when the last job in the group has exited: https://blogs.msdn.microsoft.com/oldnewthing/20130405-00/?p=4743 Closes bazelbuild#6860. PiperOrigin-RevId: 229371044
- Loading branch information