From 02ff6533bbbc5dae95959c4979765d532d9e0af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 6 Mar 2015 18:47:33 +0100 Subject: Handle Transport:controlling_socket/2 errors and close the socket --- src/ranch_acceptor.erl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/ranch_acceptor.erl') diff --git a/src/ranch_acceptor.erl b/src/ranch_acceptor.erl index 4acd04f..0a1b8a2 100644 --- a/src/ranch_acceptor.erl +++ b/src/ranch_acceptor.erl @@ -27,10 +27,14 @@ start_link(LSocket, Transport, ConnsSup) -> loop(LSocket, Transport, ConnsSup) -> _ = case Transport:accept(LSocket, infinity) of {ok, CSocket} -> - Transport:controlling_process(CSocket, 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); + case Transport:controlling_process(CSocket, ConnsSup) of + ok -> + %% 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); + {error, _} -> + Transport:close(CSocket) + end; %% 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. -- cgit v1.2.3