Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: async exceptions and readProcess_ (waitForProcess: does not exist) #47

Open
bitc opened this issue Dec 19, 2021 · 2 comments
Open

Comments

@bitc
Copy link

bitc commented Dec 19, 2021

This may be related to #38 (or a duplicate of it), but I am posting because my use case is explicitly using async exceptions.

Here is a simple program that calls readProcess_ and then attempts to cancel it, using the async library:

import Control.Concurrent
import Control.Concurrent.Async
import Control.Exception
import System.Process.Typed

main :: IO ()
main = do
  putStrLn "Start"
  a <- async $ do
    readProcess_ (proc "/bin/sleep" ["1"]) -- Sleep 1 second
  threadDelay (20 * 1000) -- Wait 20 milliseconds
  putStrLn "Canceling"
  cancel a
  putStrLn "Waiting"
  r <- waitCatch a
  print r

Here is the correct output that I expect to see (and I get about 20% of the time):

Start
Canceling
Left AsyncCancelled

But most of the time, I get this unexpected output:

Start
Canceling
Left waitForProcess: does not exist (No child processes)

That is the first bug.

The second bug is that the "cancel" line is not immediate, it seems that it doesn't actually terminate the running process, but always waits for the "sleep" process to complete (I am compiling using -threaded flag). This delay happens with both output scenarios.

Thank you

@tomjaguarpaw
Copy link
Collaborator

Hello, thanks for reporting this. I think it requires @snoyberg or someone else familiar with process internals to have a look at it.

@snoyberg
Copy link
Member

From what I can tell, this has the same root cause as #38 and requires fundamental changes to process to fix correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants