Andrea Vezzosi pushed to branch wip/romes/async-rpc at Glasgow Haskell Compiler / GHC Commits: 76c49a91 by Andrea Vezzosi at 2026-11-16T09:54:07+01:00 runWithPipes: avoid race to close their end on windows `closeCommunicationHandle` will query info about the raw handle, using windows primitives that block while a ReadFile is pending. We call it right after createProcess for `iserv`, but `iserv` might still start reading from the pipe first. If that happens then there's a deadlock, because we won't write anything for iserv to read until we are done closing its read end in our process. The fix is to use `closeHandle` directly, as that won't block for pending reads. - - - - - 1 changed file: - compiler/GHC/Runtime/Utils.hs Changes: ===================================== compiler/GHC/Runtime/Utils.hs ===================================== @@ -16,6 +16,7 @@ import System.IO import Control.Concurrent (rtsSupportsBoundThreads) import GHC.IO.Handle.Windows (handleToHANDLE) import GHC.IO.SubSystem (isWindowsNativeIO) +import System.Process.CommunicationHandle.Internal (CommunicationHandle(..)) import qualified System.Win32 as Win32 #endif @@ -30,8 +31,8 @@ runWithPipes createProc prog pre_opts opts = do (chTheyRead, wh) <- fixedCreateTheyReadWeWritePipe let args = pre_opts ++ (show chTheyWrite : show chTheyRead : opts) closeTheirs = do - closeCommunicationHandle chTheyWrite - closeCommunicationHandle chTheyRead + closeTheirEnd chTheyWrite + closeTheirEnd chTheyRead -- These handles have no finalizers, so close them ourselves if the spawn fails. ph <- createProc (proc prog args) `onException` (closeTheirs >> hClose rh >> hClose wh) @@ -74,3 +75,10 @@ toFdHandleIfNeeded h #else toFdHandleIfNeeded = return #endif + +closeTheirEnd :: CommunicationHandle -> IO () +#if defined(mingw32_HOST_OS) +closeTheirEnd (CommunicationHandle h) = Win32.closeHandle h +#else +closeTheirEnd = closeCommunicationHandle +#endif View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/76c49a91c44801ad9e4c9f5f6f957f4e... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/76c49a91c44801ad9e4c9f5f6f957f4e... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help