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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
33 messages Options
12
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
#8684: hWaitForInput cannot be interrupted by async exceptions on unix
------------------------------------+-------------------------------------
       Reporter:  nh2               |             Owner:
           Type:  bug               |            Status:  new
       Priority:  normal            |         Milestone:
      Component:  libraries/base    |           Version:  7.6.3
       Keywords:                    |  Operating System:  Unknown/Multiple
   Architecture:  Unknown/Multiple  |   Type of failure:  None/Unknown
     Difficulty:  Unknown           |         Test Case:
     Blocked By:                    |          Blocking:
Related Tickets:                    |
------------------------------------+-------------------------------------
 http://hackage.haskell.org/package/base-4.6.0.1/docs/System-Timeout.html

 claims that {{{timeout}}} can interrupt {{{hWaitForInput}}}, but in fact
 that's false (e.g. mentioned in
 https://ghc.haskell.org/trac/ghc/ticket/7353#comment:4).

 {{{
 -- import Control.Concurrent
 import System.IO
 import System.Timeout

 main = timeout (1 * 1000000) $ hWaitForInput stdin (5 * 1000)
 }}}

 will not be killed after 1 second, but instead wait for the full 5 seconds
 timeout passed to {{{hWaitForInput}}}.

 The implementation is {{{ready}}} at
 http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-IO-
 FD.html, where we have two foreign calls: {{{safe fdReady}}} and {{{unsafe
 unsafe_fdReady}}}.

 The actual C implementation is at https://github.com/haskell-
 suite/base/blob/master/cbits/inputReady.c#L16. It uses {{{select}}} on
 Unix, and does check for {{{EINTR}}}, so I believe that according to
 http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/ffi.html#ffi-
 interruptible both foreign calls can be replaced by a single
 {{{interruptible}}} one.

 Is that true?

 If not, it's a documentation bug in {{{timeout}}} at least.

 Also, does {{{interruptible}}}, apart from allowing the function to be
 interrupted, behave more like {{{safe}}} or {{{unsafe}}}?

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8684>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
ghc-tickets mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
#8684: hWaitForInput cannot be interrupted by async exceptions on unix
-------------------------------------+------------------------------------
        Reporter:  nh2               |            Owner:
            Type:  bug               |           Status:  new
        Priority:  normal            |        Milestone:
       Component:  libraries/base    |          Version:  7.6.3
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown      |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:
-------------------------------------+------------------------------------

Comment (by ezyang):

 Replying to [ticket:8684 nh2]:
 > Is that true?

 This would work fine for Unix. It would be good to test if it does the
 right thing with CancelSynchronousIO as well.

 > Also, does {{{interruptible}}}, apart from allowing the function to be
 interrupted, behave more like {{{safe}}} or {{{unsafe}}}?

 Interruptible acts like {{{safe}}}, except for the extra signal throwing
 behavior.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8684#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
ghc-tickets mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#8684: hWaitForInput cannot be interrupted by async exceptions on unix
-------------------------------------+------------------------------------
        Reporter:  nh2               |            Owner:
            Type:  bug               |           Status:  new
        Priority:  normal            |        Milestone:
       Component:  libraries/base    |          Version:  7.6.3
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown      |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:
-------------------------------------+------------------------------------

Comment (by nh2):

 Replying to [comment:1 ezyang]:
 > This would work fine for Unix. It would be good to test if it does the
 right thing with CancelSynchronousIO as well.

 Ah, great.

 I guess we should update the documentation until this is actually
 implemented.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8684#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
ghc-tickets mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#8684: hWaitForInput cannot be interrupted by async exceptions on unix
-------------------------------------+------------------------------------
        Reporter:  nh2               |            Owner:
            Type:  bug               |           Status:  new
        Priority:  normal            |        Milestone:
       Component:  libraries/base    |          Version:  7.6.3
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown      |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:
-------------------------------------+------------------------------------

Comment (by lnandor):

 I have tried to fix the bug by replacing select with pselect to ignore the
 SIGVTALRM signal sent by the runtime, but to properly terminate when
 SIGPIPE is received.
 [https://github.com/nandor/packages-base/compare/fix-8684?expand=1]
 {{{
 diff --git a/GHC/IO/FD.hs b/GHC/IO/FD.hs
 index 2023526..0b0b1de 100644
 --- a/GHC/IO/FD.hs
 +++ b/GHC/IO/FD.hs
 @@ -3,6 +3,7 @@
             , NoImplicitPrelude
             , BangPatterns
             , DeriveDataTypeable
 +           , InterruptibleFFI
    #-}
  {-# OPTIONS_GHC -fno-warn-identities #-}
  -- Whether there are identities depends on the platform
 @@ -395,7 +396,7 @@ setNonBlockingMode fd set = do

  ready :: FD -> Bool -> Int -> IO Bool
  ready fd write msecs = do
 -  r <- throwErrnoIfMinus1Retry "GHC.IO.FD.ready" $
 +  r <- throwErrnoIfMinus1 "GHC.IO.FD.ready" $
            fdReady (fdFD fd) (fromIntegral $ fromEnum $ write)
                              (fromIntegral msecs)
  #if defined(mingw32_HOST_OS)
 @@ -405,7 +406,7 @@ ready fd write msecs = do
  #endif
    return (toEnum (fromIntegral r))

 -foreign import ccall safe "fdReady"
 +foreign import ccall interruptible "fdReady"
    fdReady :: CInt -> CInt -> CInt -> CInt -> IO CInt

  --
 ---------------------------------------------------------------------------
 @@ -502,7 +503,7 @@ indicates that there's no data, we call
 threadWaitRead.
  readRawBufferPtr :: String -> FD -> Ptr Word8 -> Int -> CSize -> IO Int
  readRawBufferPtr loc !fd buf off len
    | isNonBlocking fd = unsafe_read -- unsafe is ok, it can't block
 -  | otherwise    = do r <- throwErrnoIfMinus1 loc
 +  | otherwise    = do r <- throwErrnoIfMinus1Retry loc
                                  (unsafe_fdReady (fdFD fd) 0 0 0)
                        if r /= 0
                          then read
 diff --git a/GHC/IO/Handle/Text.hs b/GHC/IO/Handle/Text.hs
 index f182e7f..31f2cac 100644
 --- a/GHC/IO/Handle/Text.hs
 +++ b/GHC/IO/Handle/Text.hs
 @@ -106,7 +106,6 @@ hWaitForInput h msecs = do
                 writeIORef haCharBuffer cbuf'

                 if not (isEmptyBuffer cbuf') then return True else do
 -
                  r <- IODevice.ready haDevice False{-read-} msecs
                  if r then do -- Call hLookAhead' to throw an EOF
                               -- exception if appropriate
 diff --git a/cbits/inputReady.c b/cbits/inputReady.c
 index 51f278f..9d51750 100644
 --- a/cbits/inputReady.c
 +++ b/cbits/inputReady.c
 @@ -22,9 +22,10 @@ fdReady(int fd, int write, int msecs, int isSock)
  #else
      ( 1 ) {
  #endif
 -       int maxfd, ready;
 +    int maxfd;
      fd_set rfd, wfd;
 -       struct timeval tv;
 +    struct timespec tv;
 +    sigset_t set;

      FD_ZERO(&rfd);
      FD_ZERO(&wfd);
 @@ -39,16 +40,14 @@ fdReady(int fd, int write, int msecs, int isSock)
       */
      maxfd = fd + 1;
      tv.tv_sec  = msecs / 1000;
 -       tv.tv_usec = (msecs % 1000) * 1000;
 +    tv.tv_nsec = (msecs % 1000) * 1000000;

 -       while ((ready = select(maxfd, &rfd, &wfd, NULL, &tv)) < 0 ) {
 -           if (errno != EINTR ) {
 -               return -1;
 -           }
 -       }
 +    /* Block SIGVTALRM */
 +    sigprocmask(SIG_BLOCK, NULL, &set);
 +    sigaddset(&set, SIGVTALRM);

      /* 1 => Input ready, 0 => not ready, -1 => error */
 -       return (ready);
 +    return pselect(maxfd, &rfd, &wfd, NULL, &tv, &set);
      }
  #if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
      else {

 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8684#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
ghc-tickets mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#8684: hWaitForInput cannot be interrupted by async exceptions on unix
-------------------------------------+------------------------------------
        Reporter:  nh2               |            Owner:
            Type:  bug               |           Status:  patch
        Priority:  normal            |        Milestone:
       Component:  libraries/base    |          Version:  7.6.3
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown      |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:
-------------------------------------+------------------------------------
Changes (by nh2):

 * status:  new => patch


--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8684#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
ghc-tickets mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#8684: hWaitForInput cannot be interrupted by async exceptions on unix
-------------------------------------+-------------------------------------
              Reporter:  nh2         |            Owner:
                  Type:  bug         |           Status:  patch
              Priority:  normal      |        Milestone:
             Component:              |          Version:  7.6.3
  libraries/base                     |         Keywords:
            Resolution:              |     Architecture:  Unknown/Multiple
      Operating System:              |       Difficulty:  Unknown
  Unknown/Multiple                   |       Blocked By:
       Type of failure:              |  Related Tickets:
  None/Unknown                       |
             Test Case:              |
              Blocking:              |
Differential Revisions:  Phab:D42    |
-------------------------------------+-------------------------------------
Changes (by thoughtpolice):

 * cc: hvr, ekmett (added)
 * differential:   => Phab:D42


--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8684#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
ghc-tickets mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#8684: hWaitForInput cannot be interrupted by async exceptions on unix
-------------------------------------+-------------------------------------
        Reporter:  nh2               |                   Owner:  snoyberg
            Type:  bug               |                  Status:  patch
        Priority:  normal            |               Milestone:
       Component:  Core Libraries    |                 Version:  7.6.3
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  None/Unknown      |  Unknown/Multiple
      Blocked By:                    |               Test Case:
 Related Tickets:                    |                Blocking:
                                     |  Differential Revisions:  Phab:D42
-------------------------------------+-------------------------------------
Changes (by snoyberg):

 * cc: core-libraries-committee@… (added)
 * owner:   => snoyberg


--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8684#comment:7>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#8684: hWaitForInput cannot be interrupted by async exceptions on unix
-------------------------------------+-------------------------------------
        Reporter:  nh2               |                Owner:  snoyberg
            Type:  bug               |               Status:  patch
        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:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D42
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by nh2):

 Ai, it seems that ghc 8.0.2 changed some behaviour here:


 {{{
 import System.IO
 import System.Timeout

 main = hWaitForInput stdin (5 * 1000)
 }}}


 On ghc 8.0.2, this crashes with `fdReady: msecs != 0, this shouldn't
 happen`.

 On ghc 8.0.1, this works as expected (doing nothing, terminating after 5
 seconds).

 Probably this commit:

 https://github.com/ghc/ghc/commit/f46369b8a1bf90a3bdc30f2b566c3a7e03672518
 #diff-f727d72230bd33b0e218d47df4738565R28

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#8684: hWaitForInput cannot be interrupted by async exceptions on unix
-------------------------------------+-------------------------------------
        Reporter:  nh2               |                Owner:  snoyberg
            Type:  bug               |               Status:  patch
        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:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D42
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Description changed by nh2:

Old description:

> http://hackage.haskell.org/package/base-4.6.0.1/docs/System-Timeout.html
>
> claims that {{{timeout}}} can interrupt {{{hWaitForInput}}}, but in fact
> that's false (e.g. mentioned in
> https://ghc.haskell.org/trac/ghc/ticket/7353#comment:4).
>
> {{{
> -- import Control.Concurrent
> import System.IO
> import System.Timeout
>
> main = timeout (1 * 1000000) $ hWaitForInput stdin (5 * 1000)
> }}}
>
> will not be killed after 1 second, but instead wait for the full 5
> seconds timeout passed to {{{hWaitForInput}}}.
>
> The implementation is {{{ready}}} at
> http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-IO-
> FD.html, where we have two foreign calls: {{{safe fdReady}}} and
> {{{unsafe unsafe_fdReady}}}.
>
> The actual C implementation is at https://github.com/haskell-
> suite/base/blob/master/cbits/inputReady.c#L16. It uses {{{select}}} on
> Unix, and does check for {{{EINTR}}}, so I believe that according to
> http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/ffi.html#ffi-
> interruptible both foreign calls can be replaced by a single
> {{{interruptible}}} one.
>
> Is that true?
>
> If not, it's a documentation bug in {{{timeout}}} at least.
>
> Also, does {{{interruptible}}}, apart from allowing the function to be
> interrupted, behave more like {{{safe}}} or {{{unsafe}}}?
New description:

 http://hackage.haskell.org/package/base-4.6.0.1/docs/System-Timeout.html

 claims that {{{timeout}}} can interrupt {{{hWaitForInput}}}, but in fact
 that's false (e.g. mentioned in
 https://ghc.haskell.org/trac/ghc/ticket/7353#comment:4).

 {{{
 -- import Control.Concurrent
 import System.IO
 import System.Timeout

 main = timeout (1 * 1000000) $ hWaitForInput stdin (5 * 1000)
 }}}

 will not be killed after 1 second, but instead wait for the full 5 seconds
 timeout passed to {{{hWaitForInput}}}.

 The implementation is {{{ready}}} at
 https://downloads.haskell.org/~ghc/7.6.3/docs/html/libraries/base/src/GHC-
 IO-FD.html, where we have two foreign calls: {{{safe fdReady}}} and
 {{{unsafe unsafe_fdReady}}}.

 The actual C implementation is at https://github.com/ghc/packages-
 base/blob/52c0b09036c36f1ed928663abb2f295fd36a88bb/cbits/inputReady.c#L16.
 It uses {{{select}}} on Unix, and does check for {{{EINTR}}}, so I believe
 that according to
 http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/ffi.html#ffi-
 interruptible both foreign calls can be replaced by a single
 {{{interruptible}}} one.

 Is that true?

 If not, it's a documentation bug in {{{timeout}}} at least.

 Also, does {{{interruptible}}}, apart from allowing the function to be
 interrupted, behave more like {{{safe}}} or {{{unsafe}}}?

--

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#8684: hWaitForInput cannot be interrupted by async exceptions on unix
-------------------------------------+-------------------------------------
        Reporter:  nh2               |                Owner:  snoyberg
            Type:  bug               |               Status:  patch
        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:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D42
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by Ben Gamari <ben@…>):

 In [changeset:"37d7c1596ee936ec6597a5c1898e1fdca7c04f77/ghc" 37d7c15/ghc]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="37d7c1596ee936ec6597a5c1898e1fdca7c04f77"
 base: Add test for #8684

 Reviewers: austin, hvr

 Subscribers: rwbarton, thomie

 Differential Revision: https://phabricator.haskell.org/D3420
 }}}

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#8684: hWaitForInput cannot be interrupted by async exceptions on unix
-------------------------------------+-------------------------------------
        Reporter:  nh2               |                Owner:  snoyberg
            Type:  bug               |               Status:  patch
        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:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D42
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by nh2):

 Replying to [comment:8 nh2]:
 > On ghc 8.0.2, this crashes with `fdReady: msecs != 0, this shouldn't
 happen`.

 This is fixed for GHC 8.2 per #13525
 (https://phabricator.haskell.org/rGHCe5732d2a28dfb8a754ee73e124e3558222a543bb)

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#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:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D42
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by bgamari):

 * status:  patch => new
 * owner:  snoyberg => (none)


Comment:

 Sorry, it looks like I was mistaken; this is in fact not fixed. The
 `timeout` does not, in fact, interrupt the `hWaitForInput`. It looks like
 Phab:D42 was never actually finished.

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#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:  13525             |             Blocking:
 Related Tickets:  #12912, #13525    |  Differential Rev(s):  Phab:D42
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by nh2):

 * blockedby:   => 13525
 * related:   => #12912, #13525


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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#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:                    |
-------------------------------------+-------------------------------------
Changes (by nh2):

 * blockedby:  13525 => 13497, 13525


Comment:

 Marking this as blocked by #13497 because that one is about getting the
 timing of `fdReady()` right.

 I believe that should be completed before making sure `fdReady()` can be
 interrupted.

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#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):

 I've implemented a work-in-progress fix for GHC 8.2
 [https://github.com/nh2/ghc/commit/d75bb46b6a16b4976a239442d90e5592ec439495
 in this commit]. It's partly based on my older commit
 [https://github.com/nh2/ghc/commit/b23420378f68af9bddcced1cee08968779c505d0
 b23420378f6].

 It makes my example from the issue description work on the `-threaded`
 runtime on Linux (other platforms yet to be tested), but for unknown
 reason it doesn't fix it for the nonthreaded runtime.

 Maybe somehow in the nonthreaded runtime `timeout` doesn't actually throw
 the other thread the kill?

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#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):

 OK new info with the power of `-debug` and `+RTS -Ds`:

 In non`-threaded`, it does raise the exception, but _after_ the entire
 `hWaitForInput` is over.

 I can see it in `cap 0: raising exception in thread 2.`, and also the
 reason:

 `timeout`'s `throwTo ` also only happens **after** `hWaitForInput` is over
 (it prints `cap 0: throwTo: from thread 1 to thread 2` only at the very
 end).

 So that means it's not the exception handling that's not working, it's the
 throwing.

 My C code returns back into Haskell land, but there is no exception there
 at the time so it continues.


 ----


 On my debug commit
 https://github.com/nh2/ghc/blob/49a5e9ce7062da7594bfd86ca7af92796b84b52a/libraries/base/cbits/inputReady.c#L53-L68
 that looks like this (relevant output without `-debug` in
 [https://gist.github.com/nh2/f543030a9b68b1530b19087d0c655115 this gist]):

 {{{
 cap 0: running thread 1 (ThreadRunGHC)
 cap 0: thread 1 stopped (suspended while making a foreign call)
 fdReady called with msecs = 20
 fdReady res = -1
 cap 0: running thread 1 (ThreadRunGHC)
 cap 0: thread 1 stopped (suspended while making a foreign call)
 fdReady called with msecs = 10
 fdReady res = -1
 cap 0: running thread 1 (ThreadRunGHC)
 cap 0: thread 1 stopped (suspended while making a foreign call)
 fdReady called with msecs = 0
 fdReady res = 0
 cap 0: running thread 1 (ThreadRunGHC)
 cap 0: throwTo: from thread 1 to thread 2
         thread    2 @ 0x42001059d0 is blocked until 558048911098409
 (TSO_DIRTY)
 cap 0: raising exception in thread 2.
 cap 0: thread 1 stopped (finished)
 bound thread (1) finished
 task exiting
 }}}

 Observe here how `cap 0: throwTo: from thread 1 to thread 2` is after the
 `fdReady called with msecs = 0` (`hWaitForInput` ran its entire 5
 seconds).

 ----

 So now we just need to find out why `timeout` doesn't result in a prompt
 `cap 0: throwTo: from thread 1 to thread 2` after 1 second.

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#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):

 OK, looking at the definition of `timeout`
 [http://hackage.haskell.org/package/base-4.10.0.0/docs/src/System.Timeout.html#timeout
 here], and making an instrumented copy of it into my test case file, it
 seems that the `threadDelay n >> throwTo pid ex` is never executed.

 The `cap 0: throwTo: from thread 1 to thread 2` I observe at the very end
 is from `killThread`.

 Changing it into this

 {{{
         handleJust (\e -> if e == ex then Just () else Nothing)
                    (\_ -> return Nothing)
                    (bracket (forkIOWithUnmask $ \unmask -> do
                                  putStrLn "before unmask"
                                  unmask $ putStrLn "before delay" >>
 threadDelay n >> putStrLn "delay over" >> throwTo pid ex)
                             (\x -> putStrLn "before killThread" >>
 uninterruptibleMask_ (killThread x))
                             (\_ -> fmap Just f))
 }}}

 yields the output at the very end:

 {{{
 fdReady called with msecs = 0
 fdReady res = 1
 before killThread
 fdReady called with msecs = 0
 fdReady res = 1
 before unmask
 }}}

 and then the program terminates.

 This suggests that nothing inside `unmask` is ever executed in my non-
 threaded case, and that the thread started with `forkIOWithUnmask` doesn't
 actually run until `hWaitForInput` is over.

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#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):

 Looking at this with `+RTS -Ds` again, we get:

 {{{
 created capset 0 of type 2
 created capset 1 of type 3
 cap 0: initialised
 assigned cap 0 to capset 0
 assigned cap 0 to capset 1
 new task (taskCount: 1)
 cap 0: created thread 1
 new bound thread (1)
 cap 0: schedule()
 cap 0: running thread 1 (ThreadRunGHC)
 fdReady called with msecs = 0
 fdReady res = 1
 setup
 cap 0: created thread 2
 cap 0: thread 1 stopped (suspended while making a foreign call)
 fdReady called with msecs = 5000
 fdReady res = -1
 ...
 [lots of output running only thread 1]
 ...
 cap 0: running thread 1 (ThreadRunGHC)
 cap 0: thread 1 stopped (suspended while making a foreign call)
 fdReady called with msecs = 4690
 fdReady res = -1
 cap 0: running thread 1 (ThreadRunGHC)
 cap 0: thread 1 stopped (suspended while making a foreign call)
 fdReady called with msecs = 4680
 fdReady res = 0
 cap 0: running thread 1 (ThreadRunGHC)
 cap 0: throwTo: from thread 1 to thread 2
   thread    2 @ 0x4200105aa0 is not blocked (TSO_DIRTY)
 cap 0: throwTo: blocking on thread 2
 cap 0: thread 1 stopped (blocked on throwTo)
   thread    1 @ 0x4200105388 is blocked on a throwto message (TSO_DIRTY)
 cap 0: running thread 2 (ThreadRunGHC)
 cap 0: raising exception in thread 2.
 cap 0: waking up thread 1 on cap 0
 cap 0: thread 2 stopped (yielding)
 cap 0: running thread 1 (ThreadRunGHC)
 }}}

 So the new question here is: Why is `thread 2` (the one that contains
 `unmask $ threadDelay n >> throwTo pid ex`) never run, and `thread 1` is
 run all the time?

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#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):

 The above seems to be because in `rts/Schedule.c` only `resumeThread()` is
 called, and `schedule()` is not called.

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

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

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#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):

 I think I've got it!

 Inserting a `yield`
 [https://github.com/nh2/ghc/blob/49a5e9ce7062da7594bfd86ca7af92796b84b52a/libraries/base/GHC/IO/FD.hs#L422
 here] after `fdReady()` returns back into Haskell makes `delay over`
 appear and my example code terminate after the 1 second `timeout`.

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
12