on master help sign in
Ignore ECONNABORTED errors during accept
31d0012Reid Draper
warp/Network/Wai/Handler/Warp/Run.hs+10−3
@@ -22,6 +22,8 @@ import Data.Char (chr)
22import "iproute" Data.IP (toHostAddress, toHostAddress6)
22import "iproute" Data.IP (toHostAddress, toHostAddress6)
23import Data.IORef (IORef, newIORef, readIORef, writeIORef)
23import Data.IORef (IORef, newIORef, readIORef, writeIORef)
24import Data.Streaming.Network (bindPortTCP)
24import Data.Streaming.Network (bindPortTCP)
25+import Foreign.C.Error (Errno(..), eCONNABORTED)
26+import GHC.IO.Exception (IOException(..))
25import Network (sClose, Socket)
27import Network (sClose, Socket)
26import Network.Socket (accept, withSocketsDo, SockAddr(SockAddrInet, SockAddrInet6), setSocketOption, SocketOption(..))
28import Network.Socket (accept, withSocketsDo, SockAddr(SockAddrInet, SockAddrInet6), setSocketOption, SocketOption(..))
27import qualified Network.Socket.ByteString as Sock
29import qualified Network.Socket.ByteString as Sock
@@ -240,9 +242,14 @@ acceptConnection set getConnMaker app counter ii0 = do
240 ex <- try getConnMaker
242 ex <- try getConnMaker
241 case ex of
243 case ex of
242 Right x -> return $ Just x
244 Right x -> return $ Just x
243− Left (e :: IOError) -> do
245+ Left e -> do
246+ let eConnAborted = getErrno eCONNABORTED
247+ getErrno (Errno cInt) = cInt
248+ if ioe_errno e == Just eConnAborted
249+ then acceptNewConnection
250+ else do
244− settingsOnException set Nothing $ toException e
251+ settingsOnException set Nothing $ toException e
245− return Nothing
252+ return Nothing
246
253
247-- Fork a new worker thread for this connection maker, and ask for a
254-- Fork a new worker thread for this connection maker, and ask for a
248-- function to unmask (i.e., allow async exceptions to be thrown).
255-- function to unmask (i.e., allow async exceptions to be thrown).