Continuing the conversation from here: snapframework/snap-core#283
tl;dr Handlers seem not to correctly time out if computing a pure value causes them to overrun their time deadline.
Repro:
{-# LANGUAGE OverloadedStrings #-}
import Snap.Core
import Snap.Http.Server
import qualified Data.List as L
main = quickHttpServe hmm
hmm :: Snap ()
hmm = do
setTimeout 5
writeBS $ if L.find (==1) (repeat 0) == Just 1 then "A" else "B"
If you curl 'localhost:8000', it won't time out in 5 seconds, or seemingly ever. If you change writeBS $ to writeBS $!, though, forcing the value to WHNF is enough to properly time out.
The problem, I hypothesize, is that the hmm function is immediately returning a thunk, and thus not timing out.
My (hand-wavy) proposal is to force to WHNF (or normal form) the ByteString response body, in order to correctly time out. This'll prevent malicious input (to vulnerable handlers) from creating "permanent" un-killed response threads.
Functions I might try and update are processRequest or runServerHandler in Snap.Internal.Http.Server.Session.
I can try to hack on this but it'd be good to know if it's the right way forward first.
Continuing the conversation from here: snapframework/snap-core#283
tl;dr Handlers seem not to correctly time out if computing a pure value causes them to overrun their time deadline.
Repro:
{-# LANGUAGE OverloadedStrings #-} import Snap.Core import Snap.Http.Server import qualified Data.List as L main = quickHttpServe hmm hmm :: Snap () hmm = do setTimeout 5 writeBS $ if L.find (==1) (repeat 0) == Just 1 then "A" else "B"If you
curl 'localhost:8000', it won't time out in 5 seconds, or seemingly ever. If you changewriteBS $towriteBS $!, though, forcing the value to WHNF is enough to properly time out.The problem, I hypothesize, is that the
hmmfunction is immediately returning a thunk, and thus not timing out.My (hand-wavy) proposal is to force to WHNF (or normal form) the ByteString response body, in order to correctly time out. This'll prevent malicious input (to vulnerable handlers) from creating "permanent" un-killed response threads.
Functions I might try and update are
processRequestorrunServerHandlerinSnap.Internal.Http.Server.Session.I can try to hack on this but it'd be good to know if it's the right way forward first.