Skip to content

Conversation

@Mistuke
Copy link
Contributor

@Mistuke Mistuke commented Mar 5, 2023

The Windows kernel will release a process only when the last handle to it is closed.

This means that the call to WaitForSingleObject does 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 WaitForSingleObject the 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

@Mistuke Mistuke changed the title process: don't wait indefinitely on processes Windows: don't wait indefinitely on processes Mar 5, 2023
@Mistuke Mistuke force-pushed the wip/process-fix-wait-condition branch from 9c7662f to babf6f8 Compare March 5, 2023 12:12
Copy link
Collaborator

@snoyberg snoyberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One request: could you add an explanation of the change to the changelog?

@Mistuke Mistuke force-pushed the wip/process-fix-wait-condition branch 2 times, most recently from a8ae76b to b43a910 Compare March 11, 2023 14:04
@Mistuke
Copy link
Contributor Author

Mistuke commented Mar 11, 2023

Added a changelog entry

@Mistuke Mistuke force-pushed the wip/process-fix-wait-condition branch from b43a910 to fb0dc4f Compare March 11, 2023 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants