closeCommunicationHandle hangs on Windows if the child is already reading
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
Rechercherichtung
Start by tracing closeCommunicationHandle in System.Process.CommunicationHandle and how it closes the inherited Windows handle; the issue identifies fdToHandle, mkFD, and fdStat as the path to inspect. Reproduce the hang with the supplied CloseRepro.hs program on Windows, then check that closing the parent's copy does not block while the child is reading and the program reaches done.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
On Windows, closeCommunicationHandle blocks for as long as the child process has a read pending on the
handle it inherited. The documentation recommends closing the parent's copy after spawning the child, and
readCreateProcessWithExitCodeCommunicationHandle does the same, so a child that starts reading quickly
can deadlock with its parent.
This prints done on Linux and hangs on Windows (default I/O manager; did not try WinIO):
-- ghc -threaded CloseRepro.hs
import Control.Concurrent
import qualified Data.ByteString as B
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 <- openCommunicationHandleRead (read ch)
B.hGetSome h 1 >>= print
_ -> do
(theyRead, weWrite) <- createTheyReadWeWritePipe
self <- getExecutablePath
ph <- spawnProcess self ["child", show theyRead]
threadDelay 1000000 -- let the child start its read, otherwise it's a race.
closeCommunicationHandle theyRead -- hangs on Windows
B.hPut weWrite (B.pack [120])
hClose weWrite
_ <- waitForProcess ph
putStrLn "done"
Without the threadDelay the child can still win the race on a busy enough machine, e.g. GHC's CI.
From what I can tell, using an LLM to trace through calls, closeCommunicationHandle turns the HANDLE into a Handle before closing it, and fdToHandle calls _fstati64 (via mkFD and fdStat). The parent's copy and the child's are the same synchronous pipe, and there _fstati64 waits for the child's ReadFile to finish. Trying the calls one at a time: _fstati64 and PeekNamedPipe block, while GetFileType and CloseHandle do not. The child is waiting for the parent to write, so we get a deadlock. Because fdStat imports _fstati64 as unsafe,
every other Haskell thread in the parent stops as well.
Calling CloseHandle on the raw HANDLE avoids this, and is how I'm working around it in commit 76c49a91c44801ad9e4c9f5f6f957f4e589c964c of ghc.
- Vorherrschende Sprache
- Haskell
- Sterne
- 91
- Forks
- 93
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus haskell/process
-
bug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
-
HAVE_PIPE2 at compile time but not at runtime causes segfault on macOSEvtl. vergeben @alt-romes hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
-
posix_spawn falls back to fork() when create_group = True due to HAVE_DECL_ macro mismatchEvtl. vergeben @lei-jia-xing hat das vor 11 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 57/100
-
FreeBSD 15.1 and lower have a linker bug that affects processEvtl. vergeben @luite hat das vor 43 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 35/100
Alle Issues in haskell/process
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
haskell/bytestring#730 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
seal-harness/seal-harness#399 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
fmidue/codeworld-tasks#124 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
reflex-frp/reflex#563 ·