Skip to content

Commit 0152e8d

Browse files
Rethrow exceptions from forked threads in bye
See commit `c05ce0eb2c1adb3e29a5a95783f43fa8ed59162e` message. That was motivated by the forked threads in `bye` printing their exceptions to stdout. However, those changes may mask exceptions occuring in `bye` that we actually care about. This commit fixes that by leaving exceptions in `bye` uncaught, and simply rethrowing exceptions that occur in the forked threads of `bye` back to the main thread. No messages printed to stdout, but potentially important exceptions are still propagated.
1 parent 8d37801 commit 0152e8d

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

tls/Network/TLS/Core.hs

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
{-# LANGUAGE ScopedTypeVariables #-}
3+
{-# LANGUAGE TypeApplications #-}
34
{-# OPTIONS_HADDOCK hide #-}
45

56
module Network.TLS.Core (
@@ -98,7 +99,8 @@ getRTT ctx = do
9899
--
99100
-- this doesn't actually close the handle
100101
bye :: MonadIO m => Context -> m ()
101-
bye ctx = liftIO $ E.handle swallowSync $ do
102+
bye ctx = liftIO $ do
103+
tid <- myThreadId
102104
eof <- ctxEOF ctx
103105
tls13 <- tls13orLater ctx
104106
when (tls13 && not eof) $ do
@@ -112,8 +114,10 @@ bye ctx = liftIO $ E.handle swallowSync $ do
112114
unless recvNST $ do
113115
rtt <- getRTT ctx
114116
var <- newEmptyMVar
115-
_ <- forkIOWithUnmask $ \umask -> E.handle swallowSync $
116-
umask (void $ timeout rtt $ recvHS13 ctx chk) `E.finally` putMVar var ()
117+
_ <- forkIOWithUnmask $ \umask ->
118+
E.handle @E.SomeException (E.throwTo tid) $
119+
umask (void $ timeout rtt $ recvHS13 ctx chk)
120+
`E.finally` putMVar var ()
117121
takeMVar var
118122
else do
119123
-- receiving Client Finished
@@ -124,18 +128,12 @@ bye ctx = liftIO $ E.handle swallowSync $ do
124128
-- fixme: 1sec is good enough?
125129
let rtt = 1000000
126130
var <- newEmptyMVar
127-
_ <- forkIOWithUnmask $ \umask -> E.handle swallowSync $
128-
umask (void $ timeout rtt $ recvHS13 ctx chk) `E.finally` putMVar var ()
131+
_ <- forkIOWithUnmask $ \umask ->
132+
E.handle @E.SomeException (E.throwTo tid) $
133+
umask (void $ timeout rtt $ recvHS13 ctx chk)
134+
`E.finally` putMVar var ()
129135
takeMVar var
130136
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 ()
139137

140138
bye_ :: MonadIO m => Context -> m ()
141139
bye_ ctx = liftIO $ do

0 commit comments

Comments
 (0)