Skip to content

Avoid forkIO in bye #477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions tls/Network/TLS/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ getRTT ctx = do
--
-- this doesn't actually close the handle
bye :: MonadIO m => Context -> m ()
bye ctx = liftIO $ do
bye ctx = liftIO $ E.handle swallowSync $ do
eof <- ctxEOF ctx
tls13 <- tls13orLater ctx
when (tls13 && not eof) $ do
Expand All @@ -112,7 +112,7 @@ bye ctx = liftIO $ do
unless recvNST $ do
rtt <- getRTT ctx
var <- newEmptyMVar
_ <- forkIOWithUnmask $ \umask ->
_ <- forkIOWithUnmask $ \umask -> E.handle swallowSync $
umask (void $ timeout rtt $ recvHS13 ctx chk) `E.finally` putMVar var ()
takeMVar var
else do
Expand All @@ -124,10 +124,18 @@ bye ctx = liftIO $ do
-- fixme: 1sec is good enough?
let rtt = 1000000
var <- newEmptyMVar
_ <- forkIOWithUnmask $ \umask ->
_ <- forkIOWithUnmask $ \umask -> E.handle swallowSync $
umask (void $ timeout rtt $ recvHS13 ctx chk) `E.finally` putMVar var ()
takeMVar var
bye_ ctx
where
-- Swallow synchronous exceptions, rethrow asynchronous exceptions
swallowSync :: E.SomeException -> IO ()
swallowSync e
| Just (E.SomeAsyncException ae) <- E.fromException e
= E.throwIO ae
| otherwise
= return ()

bye_ :: MonadIO m => Context -> m ()
bye_ ctx = liftIO $ do
Expand Down
Loading