Andrea Vezzosi pushed to branch wip/romes/async-rpc at Glasgow Haskell Compiler / GHC Commits: ccd3d720 by Andrea Vezzosi at 2026-11-13T19:48:56+01:00 interp: fix runWithPipes on Windows when without -threaded Test 'static-plugin-interp-panic' happens to build without -threaded and would timeout on Windows CI. Turns out that in such a configuration the 'Handle's we get from 'System.Process.CommunicationHandle' cause the whole process to lock. Rebuilding them with 'hANDLEToHandle' fixes it. - - - - - 1 changed file: - compiler/GHC/Runtime/Utils.hs Changes: ===================================== compiler/GHC/Runtime/Utils.hs ===================================== @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + module GHC.Runtime.Utils ( runWithPipes ) @@ -10,6 +12,13 @@ import System.Process import System.Process.CommunicationHandle import System.IO +#if defined(mingw32_HOST_OS) +import Control.Concurrent (rtsSupportsBoundThreads) +import GHC.IO.Handle.Windows (handleToHANDLE) +import GHC.IO.SubSystem (isWindowsNativeIO) +import qualified System.Win32 as Win32 +#endif + -- | Spawn a process connected to us by two pipes. Important to close our copy -- of the endpoints passed to the child so each side only keeps open copies it -- needs. If we don't do that, then closing one end wouldn't interrupt reads on @@ -17,8 +26,8 @@ import System.IO runWithPipes :: (CreateProcess -> IO ProcessHandle) -> FilePath -> [String] -> [String] -> IO (ProcessHandle, Handle, Handle) runWithPipes createProc prog pre_opts opts = do - (rh, chTheyWrite) <- createWeReadTheyWritePipe - (chTheyRead, wh) <- createTheyReadWeWritePipe + (rh, chTheyWrite) <- fixedCreateWeReadTheyWritePipe + (chTheyRead, wh) <- fixedCreateTheyReadWeWritePipe let args = pre_opts ++ (show chTheyWrite : show chTheyRead : opts) closeTheirs = do closeCommunicationHandle chTheyWrite @@ -28,3 +37,40 @@ runWithPipes createProc prog pre_opts opts = do `onException` (closeTheirs >> hClose rh >> hClose wh) closeTheirs return (ph, rh, wh) + +-- | 'createWeReadTheyWritePipe', except in a non-threaded runtime on Windows +-- without WinIO. There process gives us a synchronous native 'Handle', and +-- reading from it is a safe call to @ReadFile@, which blocks every Haskell +-- thread until data arrives. As 'GHCi.Message.Async' always has a thread +-- waiting to read the pipe, no other thread would get to run. So in that case +-- we swap our end for a file descriptor 'Handle', whose reads only block the +-- reading thread. +fixedCreateWeReadTheyWritePipe :: IO (Handle, CommunicationHandle) +fixedCreateWeReadTheyWritePipe = do + (h, ch) <- createWeReadTheyWritePipe + h' <- toFdHandleIfNeeded h + return (h', ch) + +-- | 'createTheyReadWeWritePipe', with the same exception as +-- 'fixedCreateWeReadTheyWritePipe'. +fixedCreateTheyReadWeWritePipe :: IO (CommunicationHandle, Handle) +fixedCreateTheyReadWeWritePipe = do + (ch, h) <- createTheyReadWeWritePipe + h' <- toFdHandleIfNeeded h + return (ch, h') + +toFdHandleIfNeeded :: Handle -> IO Handle +#if defined(mingw32_HOST_OS) +-- The native 'Handle' has a finalizer that closes its @HANDLE@, so we wrap a +-- duplicate and close the original. +toFdHandleIfNeeded h + | not rtsSupportsBoundThreads && not isWindowsNativeIO = do + me <- Win32.getCurrentProcess + hh <- handleToHANDLE h + dup <- Win32.duplicateHandle me hh me 0 False Win32.dUPLICATE_SAME_ACCESS + hClose h + Win32.hANDLEToHandle dup + | otherwise = return h +#else +toFdHandleIfNeeded = return +#endif View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ccd3d720d05364c323d1f89625ae3e6f... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ccd3d720d05364c323d1f89625ae3e6f... 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