Browse Source

Wait in the acceptor if we get emfile errors

This should avoid using all CPU because we keep trying to accept.
Loïc Hoguin 12 years ago
parent
commit
120d37cf75
1 changed files with 5 additions and 0 deletions
  1. 5 0
      src/ranch_acceptor.erl

+ 5 - 0
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