[GHC] #8684: hWaitForInput cannot be interrupted by async exceptions on unix

GHC ghc-devs at haskell.org
Wed Nov 15 16:18:16 UTC 2017


#8684: hWaitForInput cannot be interrupted by async exceptions on unix
-------------------------------------+-------------------------------------
        Reporter:  nh2               |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Core Libraries    |              Version:  7.6.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:  13497, 13525      |             Blocking:
 Related Tickets:  #12912, #13525    |  Differential Rev(s):  Phab:D42
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by nh2):

 Some more trouble on Windows (also for `-threaded`):

 If the FD is a
 [https://github.com/ghc/ghc/blob/ghc-8.2.1-release/libraries/base/cbits/inputReady.c#L109
 FILE_TYPE_CHAR], then the implementation of `ccall interruptible`
 ([https://downloads.haskell.org/~ghc/8.2.1/docs/html/users_guide/ffi-
 chap.html#interruptible-foreign-calls see here]) via `CancelSynchronousIo`
 doesn't seem to kill the [https://github.com/nh2/ghc/blob/bug-8684
 -interruptible-hWaitForInput/libraries/base/cbits/inputReady.c#L306
 WaitForSingleObject()] invocation.

 Unfortunately, the call to
 [https://github.com/ghc/ghc/blob/ghc-8.2.1-release/rts/win32/OSThreads.c#L569
 CancelSynchronousIo(), here named pCSIO()], does not actually check the
 return value of [https://msdn.microsoft.com/en-
 us/library/windows/desktop/aa363794(v=vs.85).aspx the function], which
 returns a `BOOL success`.

 > If this function cannot find a request to cancel, the return value is 0
 (zero), and `GetLastError` returns `ERROR_NOT_FOUND`.

 In my case, when logging it, I see it returns error code 1168, which is
 `ERROR_NOT_FOUND`, so apparently nothing was cancelled.

 As a result, my example program from the issue description runs for 5
 seconds instead of one.

 With a bit more instrumentation, I get this:

 {{{
 fdReady called with msecs = 5000
 calling WaitForSingleObject
 calling pCSIO
 pCSIO ret 0
 pCSIO error: 1168
 WaitForSingleObject rc 258 (WAIT_TIMEOUT)
 }}}

 After 1 second, as expected, it's `calling pCSIO`, but it doesn't cancel
 anything due to the error, so after 5 seconds `WaitForSingleObject rc 258
 (WAIT_TIMEOUT)` happens.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8684#comment:25>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list