Explorar o código

fix(mgmt): fix client formating crash

see: https://github.com/emqx/emqx/issues/3868
JianBo He %!s(int64=5) %!d(string=hai) anos
pai
achega
9b3a6aa635

+ 2 - 2
lib-opensource/emqx_management/src/emqx_mgmt.erl

@@ -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,

+ 9 - 1
lib-opensource/emqx_management/src/emqx_mgmt_api_clients.erl

@@ -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)->