Skip to content

Commit

Permalink
Don't leak exceptions from managed threads
Browse files Browse the repository at this point in the history
  • Loading branch information
edsko committed Sep 28, 2023
1 parent 6b2d357 commit f093214
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Network/HTTP2/Arch/Manager.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- | A thread manager.
-- The manager has responsibility to spawn and kill
Expand Down Expand Up @@ -107,9 +108,10 @@ forkManagedUnmask :: Manager -> ((forall x. IO x -> IO x) -> IO ()) -> IO ()
forkManagedUnmask mgr io =
void $ mask_ $ forkIOWithUnmask $ \unmask -> do
addMyId mgr
r <- io unmask `onException` deleteMyId mgr
-- We catch the exception and do not rethrow it: we don't want the
-- exception printed to stderr.
io unmask `catch` \(_e :: SomeException) -> return ()
deleteMyId mgr
return r

-- | Adding my thread id to the kill-thread list on stopping.
--
Expand Down

0 comments on commit f093214

Please sign in to comment.