From 7366135d7ad9a3eb8332de735fe2cf5d135f5bc8 Mon Sep 17 00:00:00 2001 From: Sergey Prokhorov Date: Thu, 29 Aug 2019 19:25:16 +0200 Subject: [PATCH] Try to restart failed downstream even when there are pending connections --- src/mtp_dc_pool.erl | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/mtp_dc_pool.erl b/src/mtp_dc_pool.erl index f8aad9e..9389411 100644 --- a/src/mtp_dc_pool.erl +++ b/src/mtp_dc_pool.erl @@ -204,11 +204,12 @@ handle_down(MonRef, Pid, Reason, #state{downstreams = Ds, end end. -maybe_restart_connection(#state{pending_downstreams = [], +maybe_restart_connection(#state{pending_downstreams = Pending, downstream_monitors = DsM} = St) -> MinConnections = application:get_env(?APP, init_dc_connections, ?DEFAULT_INIT_CONNS), - OpenConnections = map_size(DsM), - case OpenConnections < MinConnections of + NumOpen = map_size(DsM), + NumPending = length(Pending), + case (NumOpen + NumPending) < MinConnections of true -> %% We have less than minimum connections. Just spawn new one connect(St); @@ -216,10 +217,7 @@ maybe_restart_connection(#state{pending_downstreams = [], %% We have more than minimum connections. %% Don't spawn anything, because it will be done on-demand St - end; -maybe_restart_connection(St) -> - %% We already have pending connections. Just wait for them to complete - St. + end. maybe_spawn_connection(CurrentMin, #state{pending_downstreams = Pending} = St) ->