]> granicus.if.org Git - ejabberd/commitdiff
Report connection error before waiting for resumption
authorEvgeny Khramtsov <ekhramtsov@process-one.net>
Tue, 6 Aug 2019 13:18:04 +0000 (16:18 +0300)
committerEvgeny Khramtsov <ekhramtsov@process-one.net>
Tue, 6 Aug 2019 13:18:04 +0000 (16:18 +0300)
In other words don't hide the reason why c2s connection has failed

src/ejabberd_c2s.erl
src/mod_stream_mgmt.erl

index f0c609eb7cf2f1cae9b4c2032977edf2687897e4..22b72304183818e41169329d89f1b3d682d3a235 100644 (file)
@@ -44,7 +44,7 @@
 %% API
 -export([get_presence/1, set_presence/2, resend_presence/1, resend_presence/2,
         open_session/1, call/3, cast/2, send/2, close/1, close/2, stop/1,
-        reply/2, copy_state/2, set_timeout/2, route/2,
+        reply/2, copy_state/2, set_timeout/2, route/2, format_reason/2,
         host_up/1, host_down/1, send_ws_ping/1, bounce_message_queue/2]).
 
 -include("xmpp.hrl").
index ced5424a81337e0de28972fc3aba9d9bc232feb9..042efc249ae04af797906cfe7e6334c808327b9c 100644 (file)
@@ -239,8 +239,8 @@ c2s_handle_info(#{mgmt_ack_timer := TRef, jid := JID, mod := Mod} = State,
                {timeout, TRef, ack_timeout}) ->
     ?DEBUG("Timed out waiting for stream management acknowledgement of ~s",
           [jid:encode(JID)]),
-    State1 = Mod:close(State),
-    {stop, transition_to_pending(State1)};
+    State1 = Mod:close(State, ack_timeout),
+    {stop, transition_to_pending(State1, ack_timeout)};
 c2s_handle_info(#{mgmt_state := pending, lang := Lang,
                  mgmt_pending_timer := TRef, jid := JID, mod := Mod} = State,
                {timeout, TRef, pending_timeout}) ->
@@ -268,8 +268,8 @@ c2s_handle_info(State, _) ->
 
 c2s_closed(State, {stream, _}) ->
     State;
-c2s_closed(#{mgmt_state := active} = State, _Reason) ->
-    {stop, transition_to_pending(State)};
+c2s_closed(#{mgmt_state := active} = State, Reason) ->
+    {stop, transition_to_pending(State, Reason)};
 c2s_closed(State, _Reason) ->
     State.
 
@@ -439,19 +439,22 @@ handle_resume(#{user := User, lserver := LServer,
            {error, send(State, El)}
     end.
 
--spec transition_to_pending(state()) -> state().
+-spec transition_to_pending(state(), _) -> state().
 transition_to_pending(#{mgmt_state := active, mod := Mod,
-                       mgmt_timeout := 0} = State) ->
+                       mgmt_timeout := 0} = State, _Reason) ->
     Mod:stop(State);
-transition_to_pending(#{mgmt_state := active, jid := JID,
-                       lserver := LServer, mgmt_timeout := Timeout} = State) ->
+transition_to_pending(#{mgmt_state := active, jid := JID, socket := Socket,
+                       lserver := LServer, mgmt_timeout := Timeout} = State,
+                     Reason) ->
     State1 = cancel_ack_timer(State),
-    ?INFO_MSG("Waiting ~B seconds for resumption of stream for ~s",
-             [Timeout div 1000, jid:encode(JID)]),
+    ?INFO_MSG("(~s) Closing c2s connection for ~s: ~s; "
+             "waiting ~B seconds for stream resumption",
+             [xmpp_socket:pp(Socket), jid:encode(JID),
+              format_reason(State, Reason), Timeout div 1000]),
     TRef = erlang:start_timer(Timeout, self(), pending_timeout),
     State2 = State1#{mgmt_state => pending, mgmt_pending_timer => TRef},
     ejabberd_hooks:run_fold(c2s_session_pending, LServer, State2, []);
-transition_to_pending(State) ->
+transition_to_pending(State, _Reason) ->
     State.
 
 -spec check_h_attribute(state(), non_neg_integer()) -> state().
@@ -744,6 +747,14 @@ format_error(session_copy_timed_out) ->
 format_error(invalid_previd) ->
     ?T("Invalid 'previd' value").
 
+-spec format_reason(state(), term()) -> binary().
+format_reason(_, ack_timeout) ->
+    <<"Timed out waiting for stream acknowledgement">>;
+format_reason(#{stop_reason := {socket, ack_timeout}} = State, _) ->
+    format_reason(State, ack_timeout);
+format_reason(State, Reason) ->
+    ejabberd_c2s:format_reason(State, Reason).
+
 -spec log_resumption_error(binary(), binary(), error_reason()) -> ok.
 log_resumption_error(User, Server, Reason)
   when Reason == invalid_previd ->