Pipe blocking when input too large? (Mac OS)
- Dominant language
- Haskell
- Stars
- 91
- Forks
- 91
- PR merge metrics
- No merged PRs in 30d
Description
In simulating (`cat | less`) using `createProcess` and `CreatePipe`, I am experiencing a weird threshold on the input to `cat`. This is shrunk from a [real world problem](https://github.com/haskell/cabal/pull/7726#issuecomment-940897069).
```haskell
import System.IO
import System.Process
main = do
(Just inp, Just out, _, ph1) <- createProcess $
(proc "cat" [])
{ std_in = CreatePipe
, std_out = CreatePipe
}
-- Freezes when 'good' is replaced with 'bad' (1 line `a 64 bytes more)
hPutStr inp good
hClose inp
(_, _, _, ph2) <- createProcess $
(proc "less" [])
{ std_in = UseHandle out }
waitForProcess ph1
waitForProcess ph2
putStrLn "Program terminated successfully."
where
good = unlines $ replicate 2304 $ replicate 63 'A'
bad = unlines $ replicate 2305 $ replicate 63 'A'
```
Using the `good` input, `less` shows up presenting me the 2304 lines of 63 `A`s each.
Using the `bad` input, nothing shows up, and I can only Ctrl-C.
This is on Mac OS Mojave with GHC 9.0.1 and latest `process` (1.6.13.2).
In my original setting, the pipe was `nroff -man /dev/stdin | less` and the threshold was exactly 192kb (192 * 1024 bytes).
Note that there is no problem if I let the OS do the piping (using `shell "cat | less"`):
```haskell
main = do
(Just inp, _, _, p) <- createProcess $
(shell "cat | less")
{ std_in = CreatePipe }
hPutStr inp bad
hClose inp
waitForProcess p
putStrLn "Program terminated successfully."
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.