From 120d37cf752357a5b31ab8c94656fbfe2d2c7c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 8 Apr 2013 19:01:59 +0200 Subject: Wait in the acceptor if we get emfile errors This should avoid using all CPU because we keep trying to accept. --- src/ranch_acceptor.erl | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/ranch_acceptor.erl') diff --git a/src/ranch_acceptor.erl b/src/ranch_acceptor.erl index 44cf52d..f838b7d 100644 --- a/src/ranch_acceptor.erl +++ b/src/ranch_acceptor.erl @@ -39,6 +39,11 @@ loop(LSocket, Transport, ConnsSup) -> %% This call will not return until process has been started %% AND we are below the maximum number of connections. ranch_conns_sup:start_protocol(ConnsSup, CSocket); + %% Reduce the accept rate if we run out of file descriptors. + %% We can't accept anymore anyway, so we might as well wait + %% a little for the situation to resolve itself. + {error, emfile} -> + receive after 100 -> ok end; %% We want to crash if the listening socket got closed. {error, Reason} when Reason =/= closed -> ok -- cgit v1.2.3