Skip to content
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

delay new connection in case of exausted files #1004

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions warp/Network/Wai/Handler/Warp/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import qualified Control.Exception
import qualified Data.ByteString as S
import Data.IORef (newIORef, readIORef)
import Data.Streaming.Network (bindPortTCP)
import Foreign.C.Error (Errno (..), eCONNABORTED)
import Foreign.C.Error (Errno (..), eCONNABORTED, eMFILE)
import GHC.Conc (threadDelay)
import GHC.IO.Exception (IOErrorType (..), IOException (..))
import Network.Socket (
SockAddr,
Expand Down Expand Up @@ -305,13 +306,17 @@ acceptConnection set getConnMaker app counter ii = do
case ex of
Right x -> return $ Just x
Left e -> do
let eConnAborted = getErrno eCONNABORTED
getErrno (Errno cInt) = cInt
if ioe_errno e == Just eConnAborted
then acceptNewConnection
else do
settingsOnException set Nothing $ toException e
return Nothing
let getErrno (Errno cInt) = cInt
isErrno err = ioe_errno e == Just (getErrno err)
case () of
_ | isErrno eCONNABORTED -> acceptNewConnection
| isErrno eMFILE -> do
settingsOnException set Nothing $ toException e
threadDelay 100000
acceptNewConnection
| otherwise -> do
settingsOnException set Nothing $ toException e
return Nothing

-- Fork a new worker thread for this connection maker, and ask for a
-- function to unmask (i.e., allow async exceptions to be thrown).
Expand Down