Skip to content

Does not work with async exceptions #107

Description

@ndmitchell

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

Activity

  1. nh2 commented on Nov 6, 2017

    @nh2
    Member

    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.

  2. simonmar commented on Nov 8, 2017

    @simonmar
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions