CommunicationHandle pipes block every thread in the non-threaded RTS on Windows
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 57/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 领域
- backend
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Haskell
- 星标
- 91
- 派生
- 93
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 天 新手友好度 48/100
-
FreeBSD 15.1 and lower have a linker bug that affects process可能已有人在做 @luite 于 43 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
相似的 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 ·