Kaynağa Gözat

Fix session termiated without ws_channel

terry-xiaoyu 6 yıl önce
ebeveyn
işleme
721e7c4804
3 değiştirilmiş dosya ile 12 ekleme ve 13 silme
  1. 5 1
      src/emqx_channel.erl
  2. 1 11
      src/emqx_session.erl
  3. 6 1
      src/emqx_ws_channel.erl

+ 5 - 1
src/emqx_channel.erl

@@ -371,7 +371,9 @@ handle(info, Info = {'EXIT', SessionPid, Reason}, State = #state{proto_state = P
         undefined ->
             ?LOG(error, "Unexpected EXIT: ~p", [Info]),
             {keep_state, State};
-        SessionPid -> shutdown(Reason, State)
+        SessionPid ->
+            ?LOG(error, "Session ~p termiated: ~p", [SessionPid, Reason]),
+            shutdown(Reason, State)
     end;
 
 handle(info, Info, State) ->
@@ -508,6 +510,8 @@ maybe_gc(_, State) -> State.
 reply(From, Reply, State) ->
     {keep_state, State, [{reply, From, Reply}]}.
 
+shutdown(Reason = {shutdown, _}, State) ->
+    stop(Reason, State);
 shutdown(Reason, State) ->
     stop({shutdown, Reason}, State).
 

+ 1 - 11
src/emqx_session.erl

@@ -652,23 +652,13 @@ handle_info(Info, State) ->
 
 terminate(Reason, #state{will_msg = WillMsg,
                          client_id = ClientId,
-                         username = Username,
-                         conn_pid = ConnPid,
-                         old_conn_pid = OldConnPid}) ->
+                         username = Username}) ->
     send_willmsg(WillMsg),
-    [maybe_shutdown(Pid, Reason) || Pid <- [ConnPid, OldConnPid]],
     ok = emqx_hooks:run('session.terminated', [#{client_id => ClientId, username => Username}, Reason]).
 
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
 
-maybe_shutdown(undefined, _Reason) ->
-    ok;
-maybe_shutdown(Pid, normal) ->
-    Pid ! {shutdown, normal};
-maybe_shutdown(Pid, Reason) ->
-    exit(Pid, Reason).
-
 %%------------------------------------------------------------------------------
 %% Internal functions
 %%------------------------------------------------------------------------------

+ 6 - 1
src/emqx_ws_channel.erl

@@ -304,7 +304,9 @@ websocket_info(Info = {'EXIT', SessionPid, Reason}, State = #state{proto_state =
         undefined ->
             ?LOG(error, "Unexpected EXIT: ~p", [Info]),
             {ok, State};
-        SessionPid -> shutdown(Reason, State)
+        SessionPid ->
+            ?LOG(error, "Session ~p termiated: ~p", [SessionPid, Reason]),
+            shutdown(Reason, State)
     end;
 
 websocket_info(Info, State) ->
@@ -360,6 +362,9 @@ ensure_stats_timer(State = #state{enable_stats = true,
 ensure_stats_timer(State) ->
     State.
 
+shutdown(Reason = {shutdown, _}, State) ->
+    self() ! {stop, Reason},
+    {ok, State};
 shutdown(Reason, State) ->
     %% Fix the issue#2591(https://github.com/emqx/emqx/issues/2591#issuecomment-500278696)
     self() ! {stop, {shutdown, Reason}},