Merge pull request #11042 from zhongwencool/max-connections-string
fix: api_listener crash when setting max_connnections as string
This commit is contained in:
commit
86d3b702d7
|
@ -116,6 +116,7 @@ format_raw_listeners({Type0, Conf}) ->
|
||||||
fun
|
fun
|
||||||
({LName, LConf0}) when is_map(LConf0) ->
|
({LName, LConf0}) when is_map(LConf0) ->
|
||||||
Bind = parse_bind(LConf0),
|
Bind = parse_bind(LConf0),
|
||||||
|
MaxConn = maps:get(<<"max_connections">>, LConf0, default_max_conn()),
|
||||||
Running = is_running(Type, listener_id(Type, LName), LConf0#{bind => Bind}),
|
Running = is_running(Type, listener_id(Type, LName), LConf0#{bind => Bind}),
|
||||||
LConf1 = maps:remove(<<"authentication">>, LConf0),
|
LConf1 = maps:remove(<<"authentication">>, LConf0),
|
||||||
LConf2 = maps:put(<<"running">>, Running, LConf1),
|
LConf2 = maps:put(<<"running">>, Running, LConf1),
|
||||||
|
@ -124,7 +125,10 @@ format_raw_listeners({Type0, Conf}) ->
|
||||||
true -> current_conns(Type, LName, Bind);
|
true -> current_conns(Type, LName, Bind);
|
||||||
false -> 0
|
false -> 0
|
||||||
end,
|
end,
|
||||||
LConf = maps:put(<<"current_connections">>, CurrConn, LConf2),
|
LConf = maps:merge(LConf2, #{
|
||||||
|
<<"current_connections">> => CurrConn,
|
||||||
|
<<"max_connections">> => ensure_max_conns(MaxConn)
|
||||||
|
}),
|
||||||
{true, {Type0, LName, LConf}};
|
{true, {Type0, LName, LConf}};
|
||||||
({_LName, _MarkDel}) ->
|
({_LName, _MarkDel}) ->
|
||||||
false
|
false
|
||||||
|
@ -994,3 +998,7 @@ unregister_ocsp_stapling_refresh(Type, Name) ->
|
||||||
|
|
||||||
default_max_conn() ->
|
default_max_conn() ->
|
||||||
<<"infinity">>.
|
<<"infinity">>.
|
||||||
|
|
||||||
|
ensure_max_conns(<<"infinity">>) -> <<"infinity">>;
|
||||||
|
ensure_max_conns(MaxConn) when is_binary(MaxConn) -> binary_to_integer(MaxConn);
|
||||||
|
ensure_max_conns(MaxConn) -> MaxConn.
|
||||||
|
|
|
@ -140,6 +140,16 @@ t_list_listeners(Config) when is_list(Config) ->
|
||||||
?assertMatch(#{<<"max_connections">> := <<"infinity">>}, Create),
|
?assertMatch(#{<<"max_connections">> := <<"infinity">>}, Create),
|
||||||
?assert(is_running(NewListenerId)),
|
?assert(is_running(NewListenerId)),
|
||||||
|
|
||||||
|
Update2 = request(put, NewPath, [], Create#{<<"max_connections">> => 100}),
|
||||||
|
?assertMatch(#{<<"max_connections">> := 100}, Update2),
|
||||||
|
Get2 = request(get, NewPath, [], []),
|
||||||
|
?assertMatch(#{<<"max_connections">> := 100}, Get2),
|
||||||
|
|
||||||
|
Update3 = request(put, NewPath, [], Create#{<<"max_connections">> => <<"123">>}),
|
||||||
|
?assertMatch(#{<<"max_connections">> := 123}, Update3),
|
||||||
|
Get3 = request(get, NewPath, [], []),
|
||||||
|
?assertMatch(#{<<"max_connections">> := 123}, Get3),
|
||||||
|
|
||||||
%% delete
|
%% delete
|
||||||
?assertEqual([], delete(NewPath)),
|
?assertEqual([], delete(NewPath)),
|
||||||
?assertEqual({error, not_found}, is_running(NewListenerId)),
|
?assertEqual({error, not_found}, is_running(NewListenerId)),
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix crash on `/api/listeners` when listener's max_connections is set to a string.
|
Loading…
Reference in New Issue