Skip to content

Windows: don't wait indefinitely on processes - #277

Merged
snoyberg merged 1 commit into
haskell:masterfrom
Mistuke:wip/process-fix-wait-condition
Mar 12, 2023
Merged

Windows: don't wait indefinitely on processes#277
snoyberg merged 1 commit into
haskell:masterfrom
Mistuke:wip/process-fix-wait-condition

Conversation

@Mistuke

@Mistuke Mistuke commented Mar 5, 2023

Copy link
Copy Markdown
Contributor

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
Comment thread cbits/win32/runProcess.c Outdated
@Mistuke
Mistuke force-pushed the wip/process-fix-wait-condition branch from 9c7662f to babf6f8 Compare March 5, 2023 12:12

@snoyberg snoyberg left a comment

Copy link
Copy Markdown
Collaborator

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

Mistuke commented Mar 11, 2023

Copy link
Copy Markdown
Contributor Author

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