fix(emqx_cm): do not log noproc as error
1. websocket call exit with noproc reason. 2. do not capture stacktrace when no need for it
This commit is contained in:
parent
cace9341a0
commit
4e1798e3f3
|
@ -3,6 +3,7 @@
|
||||||
[
|
[
|
||||||
{"4.3.1", [
|
{"4.3.1", [
|
||||||
{load_module, emqx_connection, brutal_purge, soft_purge, []},
|
{load_module, emqx_connection, brutal_purge, soft_purge, []},
|
||||||
|
{load_module, emqx_cm, brutal_purge, soft_purge, []},
|
||||||
{load_module, emqx_congestion, brutal_purge, soft_purge, []},
|
{load_module, emqx_congestion, brutal_purge, soft_purge, []},
|
||||||
{load_module, emqx_node_dump, brutal_purge, soft_purge, []}
|
{load_module, emqx_node_dump, brutal_purge, soft_purge, []}
|
||||||
]},
|
]},
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
[
|
[
|
||||||
{"4.3.1", [
|
{"4.3.1", [
|
||||||
{load_module, emqx_connection, brutal_purge, soft_purge, []},
|
{load_module, emqx_connection, brutal_purge, soft_purge, []},
|
||||||
|
{load_module, emqx_cm, brutal_purge, soft_purge, []},
|
||||||
{load_module, emqx_congestion, brutal_purge, soft_purge, []},
|
{load_module, emqx_congestion, brutal_purge, soft_purge, []},
|
||||||
{load_module, emqx_node_dump, brutal_purge, soft_purge, []}
|
{load_module, emqx_node_dump, brutal_purge, soft_purge, []}
|
||||||
]},
|
]},
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
-include("emqx.hrl").
|
-include("emqx.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
-include("types.hrl").
|
-include("types.hrl").
|
||||||
|
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||||
|
|
||||||
-logger_header("[CM]").
|
-logger_header("[CM]").
|
||||||
|
|
||||||
|
@ -279,18 +280,25 @@ takeover_session(ClientId, ChanPid) ->
|
||||||
discard_session(ClientId) when is_binary(ClientId) ->
|
discard_session(ClientId) when is_binary(ClientId) ->
|
||||||
case lookup_channels(ClientId) of
|
case lookup_channels(ClientId) of
|
||||||
[] -> ok;
|
[] -> ok;
|
||||||
ChanPids ->
|
ChanPids -> lists:foreach(fun(Pid) -> do_discard_session(ClientId, Pid) end, ChanPids)
|
||||||
lists:foreach(
|
end.
|
||||||
fun(ChanPid) ->
|
|
||||||
|
do_discard_session(ClientId, Pid) ->
|
||||||
try
|
try
|
||||||
discard_session(ClientId, ChanPid)
|
discard_session(ClientId, Pid)
|
||||||
catch
|
catch
|
||||||
_:{noproc,_}:_Stk -> ok;
|
_ : noproc -> % emqx_ws_connection: call
|
||||||
_:{{shutdown,_},_}:_Stk -> ok;
|
?tp(debug, "session_already_gone", #{pid => Pid}),
|
||||||
_:Error:_Stk ->
|
ok;
|
||||||
?LOG(error, "Failed to discard ~0p: ~0p", [ChanPid, Error])
|
_ : {noproc, _} -> % emqx_connection: gen_server:call
|
||||||
end
|
?tp(debug, "session_already_gone", #{pid => Pid}),
|
||||||
end, ChanPids)
|
ok;
|
||||||
|
_ : {{shutdown, _}, _} ->
|
||||||
|
?tp(debug, "session_already_shutdown", #{pid => Pid}),
|
||||||
|
ok;
|
||||||
|
_ : Error : St ->
|
||||||
|
?tp(error, "failed_to_discard_session",
|
||||||
|
#{pid => Pid, reason => Error, stacktrace=>St})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
discard_session(ClientId, ChanPid) when node(ChanPid) == node() ->
|
discard_session(ClientId, ChanPid) when node(ChanPid) == node() ->
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
-include_lib("emqx/include/emqx.hrl").
|
-include_lib("emqx/include/emqx.hrl").
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||||
|
|
||||||
-define(CM, emqx_cm).
|
-define(CM, emqx_cm).
|
||||||
-define(ChanInfo,#{conninfo =>
|
-define(ChanInfo,#{conninfo =>
|
||||||
|
@ -179,6 +180,18 @@ t_discard_session(_) ->
|
||||||
ok = emqx_cm:unregister_channel(<<"clientid">>),
|
ok = emqx_cm:unregister_channel(<<"clientid">>),
|
||||||
ok = meck:unload(emqx_connection).
|
ok = meck:unload(emqx_connection).
|
||||||
|
|
||||||
|
t_discard_session_race(_) ->
|
||||||
|
ok = snabbkaffe:start_trace(),
|
||||||
|
#{conninfo := ConnInfo0} = ?ChanInfo,
|
||||||
|
ConnInfo = ConnInfo0#{conn_mod := emqx_ws_connection},
|
||||||
|
{Pid, Ref} = spawn_monitor(fun() -> receive stop -> exit(normal) end end),
|
||||||
|
ok = emqx_cm:register_channel(<<"clientid">>, Pid, ConnInfo),
|
||||||
|
Pid ! stop,
|
||||||
|
receive {'DOWN', Ref, process, Pid, normal} -> ok end,
|
||||||
|
ok = emqx_cm:discard_session(<<"clientid">>),
|
||||||
|
{ok, _} = ?block_until(#{?snk_kind := "session_already_gone", pid := Pid}, 1000),
|
||||||
|
snabbkaffe:stop().
|
||||||
|
|
||||||
t_takeover_session(_) ->
|
t_takeover_session(_) ->
|
||||||
#{conninfo := ConnInfo} = ?ChanInfo,
|
#{conninfo := ConnInfo} = ?ChanInfo,
|
||||||
{error, not_found} = emqx_cm:takeover_session(<<"clientid">>),
|
{error, not_found} = emqx_cm:takeover_session(<<"clientid">>),
|
||||||
|
|
Loading…
Reference in New Issue