Skip to content

Pipe blocking when input too large? (Mac OS) #218

Open
@andreasabel

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.

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 As 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"):

main = do

  (Just inp, _, _, p) <- createProcess $
    (shell "cat | less")
      { std_in = CreatePipe }
  hPutStr inp bad
  hClose inp

  waitForProcess p
  putStrLn "Program terminated successfully."

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions