winio: Fix Handle mode on inherited handles. #245
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.
There's a small bug in the modes that we create handles with when we make inheritable handles.
We create both the input and output handles with
FILE_FLAG_OVERLAPPED.This is OK as long as the program being called is also not using IOCP. For the majority of the program
usually called this is the case and so we never noticed the bug in testing.
However when calling an application which is also using overlapped IO or uses the kernel low level
async APIs then the spawned application will misbehave because the operation would unexpectedly
become asynchronous. This is the case with any program using Microsoft VC++'s stdlibs to read pipes.
The fix is to only mark handles with
FILE_FLAG_OVERLAPPEDif they are not being inherited. That is,only make them asynchronous if we, the caller will be using them and not the callee.
Note that WINIO can handle synchronous handles as well, so even if some other part of the program
uses the synchronous handle it would still work correctly.
Fixes https://gitlab.haskell.org/ghc/ghc/-/issues/21610
/cc @bgamari