fix(persistent_sessions): channels can terminate without a session
This commit is contained in:
parent
48c7788d6f
commit
d2bc5e77a7
|
@ -1179,20 +1179,23 @@ terminate(_, #channel{conn_state = idle}) -> ok;
|
||||||
terminate(normal, Channel) ->
|
terminate(normal, Channel) ->
|
||||||
run_terminate_hook(normal, Channel);
|
run_terminate_hook(normal, Channel);
|
||||||
terminate({shutdown, kicked}, Channel) ->
|
terminate({shutdown, kicked}, Channel) ->
|
||||||
_ = emqx_persistent_session:persist(Channel#channel.clientinfo,
|
persist_if_session(Channel),
|
||||||
Channel#channel.conninfo,
|
|
||||||
Channel#channel.session),
|
|
||||||
run_terminate_hook(kicked, Channel);
|
run_terminate_hook(kicked, Channel);
|
||||||
terminate({shutdown, Reason}, Channel) when Reason =:= discarded;
|
terminate({shutdown, Reason}, Channel) when Reason =:= discarded;
|
||||||
Reason =:= takeovered ->
|
Reason =:= takeovered ->
|
||||||
run_terminate_hook(Reason, Channel);
|
run_terminate_hook(Reason, Channel);
|
||||||
terminate(Reason, Channel = #channel{will_msg = WillMsg}) ->
|
terminate(Reason, Channel = #channel{will_msg = WillMsg}) ->
|
||||||
(WillMsg =/= undefined) andalso publish_will_msg(WillMsg),
|
(WillMsg =/= undefined) andalso publish_will_msg(WillMsg),
|
||||||
_ = emqx_persistent_session:persist(Channel#channel.clientinfo,
|
persist_if_session(Channel),
|
||||||
Channel#channel.conninfo,
|
|
||||||
Channel#channel.session),
|
|
||||||
run_terminate_hook(Reason, Channel).
|
run_terminate_hook(Reason, Channel).
|
||||||
|
|
||||||
|
persist_if_session(#channel{session = Session} = Channel) ->
|
||||||
|
_ = [emqx_persistent_session:persist(Channel#channel.clientinfo,
|
||||||
|
Channel#channel.conninfo,
|
||||||
|
Channel#channel.session)
|
||||||
|
|| emqx_session:is_session(Session)],
|
||||||
|
ok.
|
||||||
|
|
||||||
run_terminate_hook(_Reason, #channel{session = undefined}) -> ok;
|
run_terminate_hook(_Reason, #channel{session = undefined}) -> ok;
|
||||||
run_terminate_hook(Reason, #channel{clientinfo = ClientInfo, session = Session}) ->
|
run_terminate_hook(Reason, #channel{clientinfo = ClientInfo, session = Session}) ->
|
||||||
emqx_session:terminate(ClientInfo, Reason, Session).
|
emqx_session:terminate(ClientInfo, Reason, Session).
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
|
|
||||||
-export([ info/1
|
-export([ info/1
|
||||||
, info/2
|
, info/2
|
||||||
|
, is_session/1
|
||||||
, stats/1
|
, stats/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
@ -202,6 +203,9 @@ init(Opts) ->
|
||||||
%% Info, Stats
|
%% Info, Stats
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
|
is_session(#session{}) -> true;
|
||||||
|
is_session(_) -> false.
|
||||||
|
|
||||||
%% @doc Get infos of the session.
|
%% @doc Get infos of the session.
|
||||||
-spec(info(session()) -> emqx_types:infos()).
|
-spec(info(session()) -> emqx_types:infos()).
|
||||||
info(Session) ->
|
info(Session) ->
|
||||||
|
|
Loading…
Reference in New Issue