Windows: don't wait indefinitely on processes#277
Merged
snoyberg merged 1 commit intohaskell:masterfrom Mar 12, 2023
Merged
Conversation
This was referenced Mar 5, 2023
robx
reviewed
Mar 5, 2023
9c7662f to
babf6f8
Compare
snoyberg
requested changes
Mar 8, 2023
Collaborator
snoyberg
left a comment
There was a problem hiding this comment.
LGTM. One request: could you add an explanation of the change to the changelog?
a8ae76b to
b43a910
Compare
Contributor
Author
|
Added a changelog entry |
b43a910 to
fb0dc4f
Compare
snoyberg
approved these changes
Mar 12, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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