Skip to content

Commit 9529569

Browse files
committed
ignoring error from shutdown in gracefulClose
When a socket is already closed, shutdown throws an exception.
1 parent 4d82bf1 commit 9529569

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Network/Socket/Shutdown.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ gracefulClose s tmout = sendRecvFIN `E.finally` close s
5151
where
5252
sendRecvFIN = do
5353
-- Sending TCP FIN.
54-
shutdown s ShutdownSend
55-
-- Waiting TCP FIN.
56-
E.bracket (mallocBytes bufSize) free $ \buf -> do
57-
{-# SCC "" #-} recvEOFloop buf
54+
ex <- E.try $ shutdown s ShutdownSend
55+
case ex of
56+
Left (E.SomeException _) -> return ()
57+
Right () -> do
58+
-- Waiting TCP FIN.
59+
E.bracket (mallocBytes bufSize) free $ \buf -> do
60+
{-# SCC "" #-} recvEOFloop buf
5861
-- milliseconds. Taken from BSD fast clock value.
5962
clock = 200
6063
recvEOFloop buf = loop 0

0 commit comments

Comments
 (0)