Fix a race condition in Bazel's Windows process management.
Fix a race condition in Bazel's Windows process management.

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

PiperOrigin-RevId: 223812853

twitter-forks/bazel,twitter-forks/bazel,werkt/bazel,perezd/bazel,akira-baruah/bazel,perezd/bazel,aehlig/bazel,dslomov/bazel-windows,davidzchen/bazel,dslomov/bazel,dslomov/bazel,dslomov/bazel,ulfjack/bazel,ulfjack/bazel,bazelbuild/bazel,dslomov/bazel-windows,dslomov/bazel,aehlig/bazel,akira-baruah/bazel,safarmer/bazel,meteorcloudy/bazel,meteorcloudy/bazel,davidzchen/bazel,safarmer/bazel,ulfjack/bazel,twitter-forks/bazel,werkt/bazel,werkt/bazel,akira-baruah/bazel,perezd/bazel,aehlig/bazel,aehlig/bazel,meteorcloudy/bazel,katre/bazel,ButterflyNetwork/bazel,safarmer/bazel,dslomov/bazel,ButterflyNetwork/bazel,safarmer/bazel,cushon/bazel,ButterflyNetwork/bazel,meteorcloudy/bazel,werkt/bazel,twitter-forks/bazel,aehlig/bazel,dslomov/bazel-windows,bazelbuild/bazel,ulfjack/bazel,ulfjack/bazel,katre/bazel,dslomov/bazel-windows,meteorcloudy/bazel,akira-baruah/bazel,ButterflyNetwork/bazel,twitter-forks/bazel,twitter-forks/bazel,perezd/bazel,aehlig/bazel,ulfjack/bazel,aehlig/bazel,perezd/bazel,katre/bazel,akira-baruah/bazel,perezd/bazel,dslomov/bazel,ulfjack/bazel,katre/bazel,bazelbuild/bazel,werkt/bazel,dslomov/bazel,safarmer/bazel,werkt/bazel,bazelbuild/bazel,bazelbuild/bazel,akira-baruah/bazel,dslomov/bazel-windows,bazelbuild/bazel,katre/bazel,cushon/bazel,cushon/bazel,davidzchen/bazel,twitter-forks/bazel,ButterflyNetwork/bazel,davidzchen/bazel,katre/bazel,dslomov/bazel-windows,safarmer/bazel,meteorcloudy/bazel,ButterflyNetwork/bazel,cushon/bazel,meteorcloudy/bazel,cushon/bazel,davidzchen/bazel,davidzchen/bazel,cushon/bazel,davidzchen/bazel,perezd/bazel