fix(gateway): fix http-api 500 issue if setting max_connections to infinity

This commit is contained in:
JianBo He 2023-06-07 18:15:14 +08:00
parent c450a1784a
commit 8df7b1a1be
2 changed files with 15 additions and 3 deletions

View File

@ -304,7 +304,6 @@ do_listeners_cluster_status(Listeners) ->
status => #{ status => #{
running => Running, running => Running,
current_connections => Curr, current_connections => Curr,
%% XXX: Since it is taken from raw-conf, it is possible a string
max_connections => int(Max) max_connections => int(Max)
} }
} }
@ -314,10 +313,15 @@ do_listeners_cluster_status(Listeners) ->
Listeners Listeners
). ).
int(infinity) ->
infinity;
int(<<"infinity">>) ->
infinity;
int(B) when is_binary(B) -> int(B) when is_binary(B) ->
binary_to_integer(B); binary_to_integer(B);
int(I) when is_integer(I) -> int(I) when is_integer(I) ->
I. I.
aggregate_listener_status(NodeStatus) -> aggregate_listener_status(NodeStatus) ->
aggregate_listener_status(NodeStatus, 0, 0, undefined). aggregate_listener_status(NodeStatus, 0, 0, undefined).
@ -330,11 +334,19 @@ aggregate_listener_status(
CurrAcc, CurrAcc,
RunningAcc RunningAcc
) -> ) ->
NMaxAcc = plus_max_connections(MaxAcc, Max),
NRunning = aggregate_running(Running, RunningAcc), NRunning = aggregate_running(Running, RunningAcc),
aggregate_listener_status(T, MaxAcc + Max, Current + CurrAcc, NRunning); aggregate_listener_status(T, NMaxAcc, Current + CurrAcc, NRunning);
aggregate_listener_status([], MaxAcc, CurrAcc, RunningAcc) -> aggregate_listener_status([], MaxAcc, CurrAcc, RunningAcc) ->
{MaxAcc, CurrAcc, RunningAcc}. {MaxAcc, CurrAcc, RunningAcc}.
plus_max_connections(_, infinity) ->
infinity;
plus_max_connections(infinity, _) ->
infinity;
plus_max_connections(A, B) when is_integer(A) andalso is_integer(B) ->
A + B.
aggregate_running(R, R) -> R; aggregate_running(R, R) -> R;
aggregate_running(R, undefined) -> R; aggregate_running(R, undefined) -> R;
aggregate_running(_, _) -> inconsistent. aggregate_running(_, _) -> inconsistent.

View File

@ -266,7 +266,7 @@ common_listener_opts() ->
)}, )},
{max_connections, {max_connections,
sc( sc(
integer(), hoconsc:union([infinity, pos_integer()]),
#{ #{
default => 1024, default => 1024,
desc => ?DESC(gateway_common_listener_max_connections) desc => ?DESC(gateway_common_listener_max_connections)