Skip to content

Commit

Permalink
fix deadlock in Numeric.Optimization.MIP.Internal.ProcessUtil
Browse files Browse the repository at this point in the history
hGetLine waiting for input blocks hSetBuffering on the same Handle
and prevents takeTMVar to happen.
  • Loading branch information
msakai committed Feb 27, 2021
1 parent cf6f494 commit 7d7eb35
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions MIP/src/Numeric/Optimization/MIP/Internal/ProcessUtil.hs
Expand Up @@ -45,6 +45,9 @@ runProcessWithOutputCallback cmd args input putMsg putErr = do
, std_out = CreatePipe
, std_err = CreatePipe
}
hSetBuffering outh LineBuffering
hSetBuffering errh LineBuffering

req <- newEmptyTMVarIO
let f act = atomically (putTMVar req act)
m1 = forever (hGetLine outh >>= \s -> f (putMsg s))
Expand All @@ -59,8 +62,6 @@ runProcessWithOutputCallback cmd args input putMsg putErr = do
-- hClose performs implicit hFlush, and thus may trigger a SIGPIPE
ignoreSigPipe $ hClose inh

hSetBuffering outh LineBuffering
hSetBuffering errh LineBuffering
let loop = join $ atomically $ msum $
[ do act <- takeTMVar req
return $ act >> loop
Expand Down

0 comments on commit 7d7eb35

Please sign in to comment.