From 554efdabcb7e3f382fb5af2aaad6194d67eca7cf Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Sun, 1 Jan 2023 11:36:46 -0500 Subject: [PATCH] catch *any* exception `listenLoop` was crashing when the client closed the connection during the handshake. How this doesn't qualify as an `IOException` is beyond me. --- ChangeLog.md | 2 ++ src/Network/Gemini/Capsule.hs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 877f2c3..e328c56 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,5 @@ # Changelog for gemcap ## Unreleased changes + +- fixed a bug that would cause the server to crash when the client aborted the handshake by rejecting the key diff --git a/src/Network/Gemini/Capsule.hs b/src/Network/Gemini/Capsule.hs index 8ef2d6c..c01f329 100644 --- a/src/Network/Gemini/Capsule.hs +++ b/src/Network/Gemini/Capsule.hs @@ -31,7 +31,7 @@ module Network.Gemini.Capsule ( ) where import Control.Concurrent (forkIO) -import Control.Exception (IOException, try) +import Control.Exception (SomeException, try) import Control.Exception.Base (bracket, finally) import Control.Monad (void) import qualified Data.Connection as C @@ -72,7 +72,7 @@ listenLoop sock params handler = do certRef <- newIORef Nothing let params' = adjustServerParams certRef params try (accept params' sock) >>= \case - Left (_::IOException) -> return () + Left (_::SomeException) -> return () Right conn -> void $ forkIO $ finally (readIORef certRef >>= runConnection conn handler) (C.close conn)