Browse Source

Fix the 'function_clause' error when session is undefined

Feng Lee 6 years ago
parent
commit
53dda48833
1 changed files with 2 additions and 0 deletions
  1. 2 0
      src/emqx_channel.erl

+ 2 - 0
src/emqx_channel.erl

@@ -153,6 +153,8 @@ attrs(session, #channel{session = Session}) ->
 attrs(Key, Channel) -> info(Key, Channel).
 attrs(Key, Channel) -> info(Key, Channel).
 
 
 -spec(stats(channel()) -> emqx_types:stats()).
 -spec(stats(channel()) -> emqx_types:stats()).
+stats(#channel{pub_stats = PubStats, session = undefined}) ->
+    maps:to_list(PubStats);
 stats(#channel{pub_stats = PubStats, session = Session}) ->
 stats(#channel{pub_stats = PubStats, session = Session}) ->
     maps:to_list(PubStats) ++ emqx_session:stats(Session).
     maps:to_list(PubStats) ++ emqx_session:stats(Session).