From 1db8290685e9cff3dfafde62de6148246075990a Mon Sep 17 00:00:00 2001 From: Jose M Perez Date: Sun, 1 Sep 2019 22:11:21 +0200 Subject: Removed connections trigger acceptors wake-up --- src/ranch_conns_sup.erl | 6 +++++- test/acceptor_SUITE.erl | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ranch_conns_sup.erl b/src/ranch_conns_sup.erl index 389deb0..9b85b25 100644 --- a/src/ranch_conns_sup.erl +++ b/src/ranch_conns_sup.erl @@ -147,8 +147,12 @@ loop(State=#state{parent=Parent, ref=Ref, conn_type=ConnType, %% Remove a connection from the count of connections. {remove_connection, Ref, Pid} -> case put(Pid, removed) of - active -> + active when Sleepers =:= [] -> loop(State, CurConns - 1, NbChildren, Sleepers); + active -> + [To|Sleepers2] = Sleepers, + To ! self(), + loop(State, CurConns - 1, NbChildren, Sleepers2); removed -> loop(State, CurConns, NbChildren, Sleepers); undefined -> diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl index 8748201..2c8b9e2 100644 --- a/test/acceptor_SUITE.erl +++ b/test/acceptor_SUITE.erl @@ -40,6 +40,7 @@ groups() -> tcp_max_connections_and_beyond, tcp_max_connections_infinity, tcp_remove_connections, + tcp_remove_connections_acceptor_wakeup, tcp_set_max_connections, tcp_set_max_connections_clean, tcp_getopts_capability, @@ -974,6 +975,24 @@ tcp_remove_connections(_) -> 0 = ranch_server:count_connections(Name), ok = ranch:stop_listener(Name). +tcp_remove_connections_acceptor_wakeup(_) -> + doc("Ensure that removed connections wake up acceptors."), + Name = name(), + {ok, _} = ranch:start_listener(Name, + ranch_tcp, #{max_connections => 1, num_acceptors => 1}, + remove_conn_and_wait_protocol, [{remove, true, infinity}]), + Port = ranch:get_port(Name), + ConnectOptions = [binary, {active, false}], + Localhost = "localhost", + {ok, Socket1} = gen_tcp:connect(Localhost, Port, ConnectOptions), + {ok, Socket2} = gen_tcp:connect(Localhost, Port, ConnectOptions), + {ok, Socket3} = gen_tcp:connect(Localhost, Port, ConnectOptions), + ok = gen_tcp:send(Socket3, <<"bye">>), + true = maps:get(all_connections, ranch:info(Name)) >= 2, + ok = gen_tcp:send(Socket1, <<"bye">>), + ok = gen_tcp:send(Socket2, <<"bye">>), + ok = ranch:stop_listener(Name). + tcp_set_max_connections(_) -> doc("Ensure that changing the max_connections option to a larger value allows for more connections."), Name = name(), -- cgit v1.2.3