gregwebs/Shelly.hs

Strange Async hang

Closed this issue · 5 comments

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?

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

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

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.

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

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.