[GHC] #5902: Cannot tell from an exception handler whether the exception was asynchronous

GHC cvs-ghc at haskell.org
Thu May 2 14:15:44 CEST 2013


#5902: Cannot tell from an exception handler whether the exception was
asynchronous
---------------------------------+------------------------------------------
    Reporter:  simonmar          |       Owner:  simonmar        
        Type:  bug               |      Status:  new             
    Priority:  high              |   Milestone:  7.8.1           
   Component:  Compiler          |     Version:  7.4.1           
    Keywords:                    |          Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown    
  Difficulty:  Unknown           |    Testcase:                  
   Blockedby:                    |    Blocking:                  
     Related:                    |  
---------------------------------+------------------------------------------
Changes (by igloo):

  * priority:  normal => high
  * milestone:  7.6.2 => 7.8.1


Comment:

 I think we've been running into problems with this when using the GHC API,
 with the same async exception being caught multiple times.

 Here's a small testcase of what I think is going on:

 {{{
 import Control.Concurrent
 import Control.Exception
 import System.IO.Error
 import System.IO.Unsafe

 -- Our code:
 main = do tid <- myThreadId
           forkIO $ do threadDelay 1000
                       throwTo tid UserInterrupt
           print i `catch` \e -> putStrLn ("Got " ++ show (e ::
 AsyncException))
           print i `catch` \e -> putStrLn ("Got " ++ show (e ::
 AsyncException))

 -- A small simulation of the GHC API:
 f :: IO Integer
 f = (return $! sum [1..10000000]) `catchIOError` \_ -> return 3

 i :: Integer
 i = unsafePerformIO f
 }}}

 Although we only throw `UserInterrupt` once, we catch it twice:
 {{{
 $ ghc -O --make exc
 $ ./exc
 Got user interrupt
 Got user interrupt
 }}}

 Unfortunately, I can't see a workaround if you want to use async
 exceptions with the GHC API. Once you throw one, there's a chance that an
 `unsafePerformIO` thunk somewhere inside the GHC API will end up
 containing it as a synchronous exception, and then any call to the GHC API
 that uses that thunk will just throw that exception.

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



More information about the ghc-tickets mailing list