Skip to content

Commit b7734c3

Browse files
committed
Merge PR haskell-tls#477
2 parents 2dbebed + c05ce0e commit b7734c3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tls/Network/TLS/Core.hs

+11-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ getRTT ctx = do
9898
--
9999
-- this doesn't actually close the handle
100100
bye :: MonadIO m => Context -> m ()
101-
bye ctx = liftIO $ do
101+
bye ctx = liftIO $ E.handle swallowSync $ do
102102
eof <- ctxEOF ctx
103103
tls13 <- tls13orLater ctx
104104
when (tls13 && not eof) $ do
@@ -112,7 +112,7 @@ bye ctx = liftIO $ do
112112
unless recvNST $ do
113113
rtt <- getRTT ctx
114114
var <- newEmptyMVar
115-
_ <- forkIOWithUnmask $ \umask ->
115+
_ <- forkIOWithUnmask $ \umask -> E.handle swallowSync $
116116
umask (void $ timeout rtt $ recvHS13 ctx chk) `E.finally` putMVar var ()
117117
takeMVar var
118118
else do
@@ -124,10 +124,18 @@ bye ctx = liftIO $ do
124124
-- fixme: 1sec is good enough?
125125
let rtt = 1000000
126126
var <- newEmptyMVar
127-
_ <- forkIOWithUnmask $ \umask ->
127+
_ <- forkIOWithUnmask $ \umask -> E.handle swallowSync $
128128
umask (void $ timeout rtt $ recvHS13 ctx chk) `E.finally` putMVar var ()
129129
takeMVar var
130130
bye_ ctx
131+
where
132+
-- Swallow synchronous exceptions, rethrow asynchronous exceptions
133+
swallowSync :: E.SomeException -> IO ()
134+
swallowSync e
135+
| Just (E.SomeAsyncException ae) <- E.fromException e
136+
= E.throwIO ae
137+
| otherwise
138+
= return ()
131139

132140
bye_ :: MonadIO m => Context -> m ()
133141
bye_ ctx = liftIO $ do

0 commit comments

Comments
 (0)