Skip to content

Commit

Permalink
don't catch asynchronous exceptions in gracefulClose.
Browse files Browse the repository at this point in the history
Ensuring that "close" is called quickly when the thread is killed.
  • Loading branch information
kazu-yamamoto committed Nov 27, 2024
1 parent e5bfd88 commit 78704fc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Network/Socket/Shutdown.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables #-}

#include "HsNetDef.h"

Expand Down Expand Up @@ -59,7 +60,8 @@ gracefulClose s tmout0 = sendRecvFIN `E.finally` close s
-- Sending TCP FIN.
ex <- E.try $ shutdown s ShutdownSend
case ex of
Left (E.SomeException _) -> return ()
-- Don't catch asynchronous exceptions
Left (_ :: E.IOException) -> return ()
Right () -> do
-- Giving CPU time to other threads hoping that
-- FIN arrives meanwhile.
Expand Down

0 comments on commit 78704fc

Please sign in to comment.