Skip to content

Commit

Permalink
rethrowing asynchronous exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Nov 13, 2024
1 parent 39846fd commit ef79679
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions Network/HTTP2/H2/Receiver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ frameReceiver ctx@Context{..} conf@Config{..} = do
loop

sendGoaway se
| isAsyncException se = E.throwIO se
| Just GoAwayIsSent <- E.fromException se = do
waitCounter0 threadManager
enqueueControl controlQ $ CFinish GoAwayIsSent
Expand Down
1 change: 1 addition & 0 deletions Network/HTTP2/H2/Sender.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ data Switch

wrapException :: E.SomeException -> IO ()
wrapException se
| isAsyncException se = E.throwIO se
| Just GoAwayIsSent <- E.fromException se = return ()
| Just ConnectionIsClosed <- E.fromException se = return ()
| Just (e :: HTTP2Error) <- E.fromException se = E.throwIO e
Expand Down
12 changes: 11 additions & 1 deletion Network/HTTP2/H2/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ module Network.HTTP2.H2.Types where

import Control.Concurrent
import Control.Concurrent.STM
import Control.Exception (SomeException)
import Control.Exception (
Exception,
SomeAsyncException (..),
SomeException (..),
)
import qualified Control.Exception as E
import Data.IORef
import Data.Typeable
Expand Down Expand Up @@ -270,3 +274,9 @@ data Config = Config
, confPeerSockAddr :: SockAddr
-- ^ This is copied into 'Aux', if exist, on server.
}

isAsyncException :: Exception e => e -> Bool
isAsyncException e =
case E.fromException (E.toException e) of
Just (SomeAsyncException _) -> True
Nothing -> False

0 comments on commit ef79679

Please sign in to comment.