Report connection error before waiting for resumption

In other words don't hide the reason why c2s connection has failed
This commit is contained in:
Evgeny Khramtsov 2019-08-06 16:18:04 +03:00
parent 77acbab965
commit 950c209310
2 changed files with 23 additions and 12 deletions

View File

@ -44,7 +44,7 @@
%% API %% API
-export([get_presence/1, set_presence/2, resend_presence/1, resend_presence/2, -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, 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]). host_up/1, host_down/1, send_ws_ping/1, bounce_message_queue/2]).
-include("xmpp.hrl"). -include("xmpp.hrl").

View File

@ -239,8 +239,8 @@ c2s_handle_info(#{mgmt_ack_timer := TRef, jid := JID, mod := Mod} = State,
{timeout, TRef, ack_timeout}) -> {timeout, TRef, ack_timeout}) ->
?DEBUG("Timed out waiting for stream management acknowledgement of ~s", ?DEBUG("Timed out waiting for stream management acknowledgement of ~s",
[jid:encode(JID)]), [jid:encode(JID)]),
State1 = Mod:close(State), State1 = Mod:close(State, ack_timeout),
{stop, transition_to_pending(State1)}; {stop, transition_to_pending(State1, ack_timeout)};
c2s_handle_info(#{mgmt_state := pending, lang := Lang, c2s_handle_info(#{mgmt_state := pending, lang := Lang,
mgmt_pending_timer := TRef, jid := JID, mod := Mod} = State, mgmt_pending_timer := TRef, jid := JID, mod := Mod} = State,
{timeout, TRef, pending_timeout}) -> {timeout, TRef, pending_timeout}) ->
@ -268,8 +268,8 @@ c2s_handle_info(State, _) ->
c2s_closed(State, {stream, _}) -> c2s_closed(State, {stream, _}) ->
State; State;
c2s_closed(#{mgmt_state := active} = State, _Reason) -> c2s_closed(#{mgmt_state := active} = State, Reason) ->
{stop, transition_to_pending(State)}; {stop, transition_to_pending(State, Reason)};
c2s_closed(State, _Reason) -> c2s_closed(State, _Reason) ->
State. State.
@ -439,19 +439,22 @@ handle_resume(#{user := User, lserver := LServer,
{error, send(State, El)} {error, send(State, El)}
end. end.
-spec transition_to_pending(state()) -> state(). -spec transition_to_pending(state(), _) -> state().
transition_to_pending(#{mgmt_state := active, mod := Mod, transition_to_pending(#{mgmt_state := active, mod := Mod,
mgmt_timeout := 0} = State) -> mgmt_timeout := 0} = State, _Reason) ->
Mod:stop(State); Mod:stop(State);
transition_to_pending(#{mgmt_state := active, jid := JID, transition_to_pending(#{mgmt_state := active, jid := JID, socket := Socket,
lserver := LServer, mgmt_timeout := Timeout} = State) -> lserver := LServer, mgmt_timeout := Timeout} = State,
Reason) ->
State1 = cancel_ack_timer(State), State1 = cancel_ack_timer(State),
?INFO_MSG("Waiting ~B seconds for resumption of stream for ~s", ?INFO_MSG("(~s) Closing c2s connection for ~s: ~s; "
[Timeout div 1000, jid:encode(JID)]), "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), TRef = erlang:start_timer(Timeout, self(), pending_timeout),
State2 = State1#{mgmt_state => pending, mgmt_pending_timer => TRef}, State2 = State1#{mgmt_state => pending, mgmt_pending_timer => TRef},
ejabberd_hooks:run_fold(c2s_session_pending, LServer, State2, []); ejabberd_hooks:run_fold(c2s_session_pending, LServer, State2, []);
transition_to_pending(State) -> transition_to_pending(State, _Reason) ->
State. State.
-spec check_h_attribute(state(), non_neg_integer()) -> state(). -spec check_h_attribute(state(), non_neg_integer()) -> state().
@ -744,6 +747,14 @@ format_error(session_copy_timed_out) ->
format_error(invalid_previd) -> format_error(invalid_previd) ->
?T("Invalid 'previd' value"). ?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. -spec log_resumption_error(binary(), binary(), error_reason()) -> ok.
log_resumption_error(User, Server, Reason) log_resumption_error(User, Server, Reason)
when Reason == invalid_previd -> when Reason == invalid_previd ->