CommunicationHandle pipes block every thread in the non-threaded RTS on Windows
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 57/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- backend
Direzione di ricerca
Start in createCommunicationPipe, where the issue says Windows builds always use rawHANDLEToHandle; compare its runtime selection with createProcess and createPipe. Reproduce the delay with the supplied non-threaded program on Windows, then check the result with the default I/O manager and +RTS --io-manager=native. Done means the default non-threaded RTS lets threadDelay return before the child writes.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
GHC defines __IO_MANAGER_WINIO__ for every Windows build, so createCommunicationPipe always gives the
parent a native Handle made by rawHANDLEToHandle, even when the program runs with the default I/O
manager. The comment there says this is fine without WinIO at runtime. That holds with -threaded. In
the non-threaded RTS, though, reading from that Handle is a blocking ReadFile on a synchronous
HANDLE. That RTS runs every Haskell thread on one OS thread, so they all stop until data arrives. An fd
Handle does not have this problem, because in the non-threaded RTS its reads go through asyncRead#
and only the reading thread waits.
Here the child writes after 3s. On Linux, and on Windows with +RTS --io-manager=native, the
threadDelay returns after about 1s. On Windows with the default I/O manager it returns only after the
child has written:
-- ghc NonThreadedRepro.hs (without -threaded)
import Control.Concurrent
import qualified Data.ByteString as B
import GHC.Clock (getMonotonicTime)
import System.Environment
import System.IO
import System.Process
import System.Process.CommunicationHandle
main :: IO ()
main = getArgs >>= \args -> case args of
["child", ch] -> do
h <- openCommunicationHandleWrite (read ch)
threadDelay 3000000
B.hPut h (B.pack [120])
hClose h
_ -> do
(weRead, theyWrite) <- createWeReadTheyWritePipe
self <- getExecutablePath
ph <- spawnProcess self ["child", show theyWrite]
closeCommunicationHandle theyWrite
t0 <- getMonotonicTime
_ <- forkIO (B.hGetSome weRead 1 >>= print)
yield
threadDelay 1000000
t1 <- getMonotonicTime
putStrLn ("threadDelay 1000000 returned after " ++ show (t1 - t0) ++ "s")
_ <- waitForProcess ph
return ()
createProcess and createPipe already pick an fd Handle or a native one at runtime with <!>. Doing
the same in createCommunicationPipe should fix this:
ourHandle <- ((\fd -> rawFdToHandle fd ourMode) =<< openHANDLE ourHANDLE)
<!> rawHANDLEToHandle ourHANDLE ourMode
Worked around this by swapping in an fd Handle here.
- Lingua principale
- Haskell
- Stelle
- 91
- Fork
- 93
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di haskell/process
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
HAVE_PIPE2 at compile time but not at runtime causes segfault on macOSForse già presa @alt-romes l’ha presa 3 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
posix_spawn falls back to fork() when create_group = True due to HAVE_DECL_ macro mismatchForse già presa @lei-jia-xing l’ha presa 11 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
FreeBSD 15.1 and lower have a linker bug that affects processForse già presa @luite l’ha presa 43 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
Tutte le issue di haskell/process
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
haskell/bytestring#730 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
seal-harness/seal-harness#399 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
fmidue/codeworld-tasks#124 ·
-
allow haskell-src-exts-1.24Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
reflex-frp/reflex#563 ·