closeCommunicationHandle hangs on Windows if the child is already reading
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Haskell
- スター
- 91
- フォーク
- 93
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
haskell/process のほかの issue
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
HAVE_PIPE2 at compile time but not at runtime causes segfault on macOS対応中かも @alt-romes が 3 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
posix_spawn falls back to fork() when create_group = True due to HAVE_DECL_ macro mismatch対応中かも @lei-jia-xing が 11 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 57/100
-
FreeBSD 15.1 and lower have a linker bug that affects process対応中かも @luite が 43 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
haskell/process の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
haskell/bytestring#730 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
seal-harness/seal-harness#399 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
fmidue/codeworld-tasks#124 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
reflex-frp/reflex#563 ·