Try to restart failed downstream even when there are pending connections

parent 00c0bd03
...@@ -204,11 +204,12 @@ handle_down(MonRef, Pid, Reason, #state{downstreams = Ds, ...@@ -204,11 +204,12 @@ handle_down(MonRef, Pid, Reason, #state{downstreams = Ds,
end end
end. end.
maybe_restart_connection(#state{pending_downstreams = [], maybe_restart_connection(#state{pending_downstreams = Pending,
downstream_monitors = DsM} = St) -> downstream_monitors = DsM} = St) ->
MinConnections = application:get_env(?APP, init_dc_connections, ?DEFAULT_INIT_CONNS), MinConnections = application:get_env(?APP, init_dc_connections, ?DEFAULT_INIT_CONNS),
OpenConnections = map_size(DsM), NumOpen = map_size(DsM),
case OpenConnections < MinConnections of NumPending = length(Pending),
case (NumOpen + NumPending) < MinConnections of
true -> true ->
%% We have less than minimum connections. Just spawn new one %% We have less than minimum connections. Just spawn new one
connect(St); connect(St);
...@@ -216,10 +217,7 @@ maybe_restart_connection(#state{pending_downstreams = [], ...@@ -216,10 +217,7 @@ maybe_restart_connection(#state{pending_downstreams = [],
%% We have more than minimum connections. %% We have more than minimum connections.
%% Don't spawn anything, because it will be done on-demand %% Don't spawn anything, because it will be done on-demand
St St
end; end.
maybe_restart_connection(St) ->
%% We already have pending connections. Just wait for them to complete
St.
maybe_spawn_connection(CurrentMin, #state{pending_downstreams = Pending} = St) -> maybe_spawn_connection(CurrentMin, #state{pending_downstreams = Pending} = St) ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment