gregwebs / Shelly.hs

Haskell shell scripting
BSD 3-Clause "New" or "Revised" License
418 stars 88 forks source link

Strange Async hang #133

Closed fosskers closed 7 years ago

fosskers commented 7 years ago

Hi again, still loving Shelly.

I'm experiencing a weird hang:

cast :: ERL r => Text -> Eff r ()
cast f = do
  toCast <- fileToCast f
  chronicle Info $ "Casting " <> toCast
  void . effShelly "Failed to stream to ChromeCast." . asyncSh $ do
    run_ "castnow" [toCast, "--quiet"]
    liftIO $ putStrLn "Yeah!!!"
    liftIO (myThreadId >>= killThread) -- Kill thread after casting completes.

where ERL is a type alias for a long extensible-effects signature I have, Eff is the effect Monad, and effShelly just catches any IO exception from Shelly and rethrows with extensible-effects mechanics.

Definitions aside, I'm finding that the run_ (which has in theory been forked) never returns. While the file I'm sending to ChromeCast does finish playing, run_ never returns and I never see the Yeah! printed, nor is the thread killed. The thread survives indefinitely and hogs the castnow CLI program.

Thoughts?

gregwebs commented 7 years ago

Rather than explaining extensible effects and chrome casting is it possible to make a very simple version that reproduces this problem?

fosskers commented 7 years ago

Sure, I'll fire up a pure IO example and see what happens.

fosskers commented 7 years ago

This reproduces the problem:

cast' :: Text -> IO ()
cast' t = do
  void . shelly . asyncSh $ do
    run_ "castnow" [t, "--quiet"]
    liftIO $ putStrLn "Yeah!!!"
    liftIO (myThreadId >>= killThread) -- Kill thread after casting completes.
fosskers commented 7 years ago

Interesting, when run without --quiet, castnow reports Idle... when finished playing. It doesn't usually do that when ran normally from the command line.

fosskers commented 7 years ago

It seems that when forked to the background (even normally in the terminal), castnow hangs when finished playing. This isn't a Shelly problem, then.