CommunicationHandle pipes block every thread in the non-threaded RTS on Windows
まだ誰も着手していません。
評価
- 難易度
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
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 ·