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

Does not work with async exceptions #107

Open
ndmitchell opened this issue Nov 6, 2017 · 2 comments
Open

Does not work with async exceptions #107

ndmitchell opened this issue Nov 6, 2017 · 2 comments

Comments

@ndmitchell
Copy link
Contributor

Given the code Proc.hs:

import System.Process
import System.Time.Extra

main = do
    (t, e) <- duration $ timeout 2 $ system "sleep 5s"
    print (showDuration t, e)
    (t, e) <- duration $ timeout 2 $ do
        (_, _, _, pid) <- createProcess (proc "sleep" ["5s"])
        waitForProcess pid
    print (showDuration t, e)
    (t, e) <- duration $ timeout 2 $ do
        withCreateProcess (proc "sleep" ["5s"]) $ \_ _ _ pid -> waitForProcess pid
    print (showDuration t, e)

I observe:

C:\Neil\temp>ghc Proc.hs -package=process-1.6.2.0 && proc
[1 of 1] Compiling Main             ( Proc.hs, Proc.o )
Linking Proc.exe ...
("5.06s",Just ExitSuccess)
("5.05s",Just ExitSuccess)
("5.04s",Just ExitSuccess)

C:\Neil\temp>ghc Proc.hs -package=process-1.6.2.0 -threaded && proc
[1 of 1] Compiling Main             ( Proc.hs, Proc.o )
Linking Proc.exe ...
("5.48s",Nothing)
("5.49s",Nothing)
proc: terminateProcess: permission denied (Permission denied)

Running Windows 10, 64bit GHC 8.2.1, process 1.6.2.0. Requires the extra library to be installed and the sleep binary to be on %PATH%. I would expect all these functions to die around 2s, but none of the timeouts are effective.

Originally found when debugging an upstream bug in Shake: ndmitchell/shake#538

@nh2
Copy link
Member

nh2 commented Nov 6, 2017

Possibly related to https://ghc.haskell.org/trac/ghc/ticket/8684?

That one is about not being able to timeout hWaitForInput, but it's possible that waitpid() also should be interruptible.

@simonmar
Copy link
Member

simonmar commented Nov 8, 2017

This relies on the interruptible extension to the FFI to allow the wait to be interrupted by the async exception. See https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ffi-chap.html#interruptible-foreign-calls

It works on Linux (I just checked), but perhaps not Windows. I don't remember off hand whether it is supposed to work or not.

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