Windows: don't wait indefinitely on processes #277
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Windows kernel will release a process only when the last handle to it is closed.
This means that the call to
WaitForSingleObjectdoes not return until every other process closes any handles they may have opened to the program, including pipes passed to it.However if on the Haskell side we haven't released the handle yet then we deadlock and wait indefinitely. There is a race condition in that if when we get to
WaitForSingleObjectthe kernel has already cleaned up the process then we'll return immediately, which is what is happening with the first test in the test program.The old workflow for this wait function used to be that we iterate until the process list is empty. On each we wait indefinitely.
The new workflow is different in that instead of waiting indefinitely we wait for 200ms and re-test the application. Essentially we poll the first process that doesn't return
STILL_ACTIVE. It's less efficient than before but it's the only way to avoid the race condition.Fixes #273
Fixes haskell/cabal#8688
Fixes haskell/cabal#8208
Waiting for GHC bootstrap and testsuite to finish https://gitlab.haskell.org/ghc/ghc/-/merge_requests/10080?diff_id=193677
/CC @bgamari @snoyberg