agrafix / Spock

Another Haskell web framework for rapid development
https://www.spock.li
679 stars 56 forks source link

Server closing connection after 1 minute? #151

Closed drautb closed 3 years ago

drautb commented 6 years ago

I'm relatively new to Haskell. Spock has made it very easy to get a simple server up and running. Thank you!

I have an endpoint that can sometimes take more than a minute to respond, which is expected and acceptable for our use case. However, I'm seeing some strange behavior that I can't explain.

It appears as if the server is closing the connection without sending a body when the connection has been open for a minute with no data sent. This seemed like an 'idle timeout' type of configuration, but I couldn't find anything in the Spock source or docs that indicate such a timeout exists.

Furthermore, when I add a putStrLn to the endpoint which forces evaluation of the thunk before sending the response, it works just fine! (Takes about 1m40s to complete the request) That makes me think it has something to do with laziness, but I don't have the experience yet to know where to look next.

This is what the endpoint looks like:

post "experiments/build-cnf" $ do
  spec <- jsonBody' :: ApiAction JSONSpec
  let dimacsStr = processRequests spec
  -- liftIO $ putStrLn $ "Length: " ++ (show $ length dimacsStr)
  text $ pack dimacsStr

If I uncomment the line that prints the length of the response, then it works as I hope it would.

Without that line, the connection is closed abruptly with no response at exactly 1 minute every time.

Does Spock have some kind of idle timeout that I missed? Or is this some subtle consequence of laziness? Possibly a bug? Thanks!

(The actual code is here.)

agrafix commented 3 years ago

This is probably a warp configuration: http://hackage.haskell.org/package/warp-3.3.13/docs/Network-Wai-Handler-Warp.html#t:Settings. If you call spockAsApp you'll get an Application which you can then run with custom settings using the warp functions

AshtonKem commented 3 years ago

image