fix(mgmt): fix client formating crash

see: https://github.com/emqx/emqx/issues/3868
This commit is contained in:
JianBo He 2021-02-01 11:13:47 +08:00 committed by JianBo He
parent db5ec5bbb7
commit 9b3a6aa635
2 changed files with 11 additions and 3 deletions

View File

@ -919,7 +919,7 @@ get_telemetry_data() ->
item(client, {ClientId, ChanPid}) ->
Attrs = case emqx_cm:get_chan_info(ClientId, ChanPid) of
undefined -> #{};
undefined -> throw(gone);
Attrs0 -> Attrs0
end,
Stats = case emqx_cm:get_chan_stats(ClientId, ChanPid) of
@ -933,7 +933,7 @@ item(client, {ClientId, ChanPid}) ->
_Sess -> _Sess
end,
SessCreated = maps:get(created_at, Session, maps:get(connected_at, ConnInfo)),
Connected = case maps:get(conn_state, Attrs) of
Connected = case maps:get(conn_state, Attrs, connected) of
connected -> true;
_ -> false
end,

View File

@ -250,7 +250,15 @@ parse_ratelimit_str(S) ->
%% Format
format(Items) when is_list(Items) ->
[format(Item) || Item <- Items];
lists:foldr(
fun(Item, Acc) ->
try
[format(Item) | Acc]
catch
throw:gone:_Stk ->
Acc
end
end, [], Items);
format(Key) when is_tuple(Key) ->
format(emqx_mgmt:item(client, Key));
format(Data) when is_map(Data)->