Timeout for pure values
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- haskell
- Domain
- backend, networking
Research direction
Start with the Haskell reproduction in the issue, then inspect processRequest and runServerHandler in Snap.Internal.Http.Server.Session. Trace how the ByteString response body is evaluated relative to the timeout deadline. Done means the provided handler reliably times out after five seconds without requiring writeBS $!.
Written by the indexing model from the issue text.
Description
Continuing the conversation from here: https://github.com/snapframework/snap-core/issues/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.
- Dominant language
- Haskell
- Stars
- 197
- Forks
- 87
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from snapframework/snap-server
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
snapframework/snap-server#96 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
snapframework/snap-server#94 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
snapframework/snap-server#92 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
snapframework/snap-server#85 · 8 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
snapframework/snap-server#77 · 2 comments ·
All issues in snapframework/snap-server
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
objectionary/phino#1724 ·
Maintainers usually reply within 1 day
-
infrastructure
Difficulty 1/5 Under an hour Newbie friendliness 92/100
alunduil/collection-json.hs#373 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
digital-asset/daml#23439 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100