Browse Source

fix(management): make client format function durable

JianBo He 5 years ago
parent
commit
d628c49f16
1 changed files with 6 additions and 2 deletions
  1. 6 2
      apps/emqx_management/src/emqx_mgmt.erl

+ 6 - 2
apps/emqx_management/src/emqx_mgmt.erl

@@ -866,7 +866,11 @@ item(client, {ClientId, ChanPid}) ->
             end,
     ClientInfo = maps:get(clientinfo, Attrs, #{}),
     ConnInfo = maps:get(conninfo, Attrs, #{}),
-    Session = maps:get(session, Attrs, #{}),
+    Session = case maps:get(session, Attrs, #{}) of
+                  undefined -> #{};
+                  _Sess -> _Sess
+              end,
+    SessCreated = maps:get(created_at, Session, maps:get(connected_at, ConnInfo)),
     Connected = case maps:get(conn_state, Attrs) of
                     connected -> true;
                     _ -> false
@@ -889,7 +893,7 @@ item(client, {ClientId, ChanPid}) ->
                  maps:with([clientid, username, mountpoint, is_bridge, zone], ClientInfo),
                  maps:with([clean_start, keepalive, expiry_interval, proto_name,
                             proto_ver, peername, connected_at, disconnected_at], ConnInfo),
-                 maps:with([created_at], Session)]);
+                 #{created_at => SessCreated}]);
 
 item(subscription, {{Topic, ClientId}, Options}) ->
     #{topic => Topic, clientid => ClientId, options => Options};