New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prematurely closed connections do not include request information #618
Comments
I cannot reproduce, I used the following script: #!/usr/bin/env stack
-- stack --resolver lts-8.8 script
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.Wai.Handler.Warp
import Network.HTTP.Types
import Data.Conduit
import Data.Conduit.Network
main :: IO ()
main = withApplicationSettings settings (return app) $ \port ->
runTCPClient (clientSettings port "localhost") $ \ad -> do
runConduit
$ yield "POST / HTTP/1.1\r\ncontent-length: 100\r\n\r\n"
.| appSink ad
where
settings = setOnException onExc defaultSettings
onExc (Just req) _ = putStrLn "got a request"
app :: Application
app _req send = send $ responseLBS status200 [] "Hello World!" And I got the output:
|
I fully acknowledge that this test case uses Scotty, and that the problem may lie within it and not WAI/Warp: #!/usr/bin/env stack
-- stack --system-ghc --resolver lts-8.9 script --package warp --package wai --package scotty --package http-types
{-# LANGUAGE OverloadedStrings #-}
import Control.Exception
import Network.HTTP.Types
import Network.Wai.Handler.Warp
import Network.Wai
import Web.Scotty
exHandler :: Maybe Request -> SomeException -> IO ()
exHandler Nothing _ = putStrLn "got nothing"
exHandler (Just req) _ = putStrLn "got a request"
app :: ScottyM ()
app = do
post "/" $ do
status status400
main :: IO ()
main = do
let warpSettings = setOnException exHandler
$ setPort 3000 defaultSettings
opts = Options 0 warpSettings
scottyOpts opts app
|
Alright, I think I've identified what's going on here:
Still investigating... EDIT Scratch that about the chunked request body, it's clearly not. The rest of the analysis still seems to apply. |
OK, this turned out to be quite a bit simpler: when keep-alive connections were failing, it was generating an exception, which it shouldn't do. I've added a commit to master to avoid that, can you test it out? |
I've tested it out and Warp now behaves as expected. Thank you. |
Cool, thanks for confirming. @kazu-yamamoto any objection to me cutting a release with this change? |
LGTM. @snoyberg Thank you for your work! |
If an HTTP client (such as curl) receives an HTTP error while it's sending the body of a request, it will immediately close the connection. If this happens, Warp will call the exception handler, but the
Maybe Request
will beNothing
.This is bad because it becomes impossible to audit these requests.
The text was updated successfully, but these errors were encountered: