Mistuke · GitHub

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_OVERLAPPED if 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

Read the original on github.com ↗