on master help sign in
Ignore ECONNABORTED errors during accept

ECONNABORTED is a recoverable error, and only applies to a particular socket in the accept(2) queue. It is safe to simply try accept'ing the next socket on the queue.

commit31d0012af57fced7869bfd8c40fa00ce54db2991 authorReid Draper <reiddraper@gmail.com> dateWed 18 May 2016, 11:27 (10 years ago) parent3011cad
1 file changed+10−3
warp/Network/Wai/Handler/Warp/Run.hs+10−3
warp/Network/Wai/Handler/Warp/Run.hs+10−3
@@ -22,6 +22,8 @@ import Data.Char (chr)
2222import "iproute" Data.IP (toHostAddress, toHostAddress6)
2323import Data.IORef (IORef, newIORef, readIORef, writeIORef)
2424import Data.Streaming.Network (bindPortTCP)
25+import Foreign.C.Error (Errno(..), eCONNABORTED)
26+import GHC.IO.Exception (IOException(..))
2527import Network (sClose, Socket)
2628import Network.Socket (accept, withSocketsDo, SockAddr(SockAddrInet, SockAddrInet6), setSocketOption, SocketOption(..))
2729import qualified Network.Socket.ByteString as Sock
@@ -240,9 +242,14 @@ acceptConnection set getConnMaker app counter ii0 = do
240242 ex <- try getConnMaker
241243 case ex of
242244 Right x -> return $ Just x
243− Left (e :: IOError) -> do
244− settingsOnException set Nothing $ toException e
245− return Nothing
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
251+ settingsOnException set Nothing $ toException e
252+ return Nothing
246253
247254-- Fork a new worker thread for this connection maker, and ask for a
248255-- function to unmask (i.e., allow async exceptions to be thrown).