Skip to content

Commit

Permalink
using isAsyncException around fromException
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Nov 14, 2024
1 parent 9a436e3 commit 88b67b4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions warp/Network/Wai/Handler/Warp/HTTP1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ http1server settings ii conn transport app addr th istatus src =
| Just NoKeepAliveRequest <- fromException e = return ()
-- No valid request
| Just (BadFirstLine _) <- fromException e = return ()
| isAsyncException e = throwIO e
| otherwise = do
_ <-
sendErrorResponse
Expand Down
1 change: 1 addition & 0 deletions warp/Network/Wai/Handler/Warp/HTTP2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ http2server label settings ii transport addr app h2req0 aux0 response = do
| Just E.ThreadKilled <- E.fromException e -> return ()
-- killed by the local timeout manager
| Just T.TimeoutThread <- E.fromException e -> return ()
| isAsyncException e -> E.throwIO e
| otherwise -> do
S.settingsOnException settings (Just req) e
let ersp = S.settingsOnExceptionResponse settings e
Expand Down
8 changes: 4 additions & 4 deletions warp/Network/Wai/Handler/Warp/Settings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

module Network.Wai.Handler.Warp.Settings where

import Control.Exception (SomeException, fromException)
import Control.Exception (SomeException(..), fromException, throw)
import qualified Data.ByteString.Builder as Builder
import qualified Data.ByteString.Char8 as C8
import Data.Streaming.Network (HostPreference)
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Data.Version (showVersion)
import GHC.IO (IO (IO), unsafeUnmask)
import GHC.IO.Exception (AsyncException (ThreadKilled), IOErrorType (..))
import GHC.IO.Exception (IOErrorType (..))
import GHC.Prim (fork#)
import qualified Network.HTTP.Types as H
import Network.Socket (SockAddr, Socket, accept)
Expand Down Expand Up @@ -228,12 +228,11 @@ defaultSettings =
-- Since 2.1.3
defaultShouldDisplayException :: SomeException -> Bool
defaultShouldDisplayException se
| Just ThreadKilled <- fromException se = False
| Just (_ :: InvalidRequest) <- fromException se = False
| Just (ioeGetErrorType -> et) <- fromException se
, et == ResourceVanished || et == InvalidArgument =
False
| Just TimeoutThread <- fromException se = False
| isAsyncException se = False
| otherwise = True

-- | Printing an exception to standard error
Expand All @@ -255,6 +254,7 @@ defaultOnException _ e =
-- Since 3.2.27
defaultOnExceptionResponse :: SomeException -> Response
defaultOnExceptionResponse e
| isAsyncException e = throw e
| Just PayloadTooLarge <- fromException e =
responseLBS
H.status413
Expand Down

0 comments on commit 88b67b4

Please sign in to comment.