diff options
author | Badlop <badlop@process-one.net> | 2019-02-01 16:21:58 +0100 |
---|---|---|
committer | Badlop <badlop@process-one.net> | 2019-02-01 16:21:58 +0100 |
commit | 8baced0d8bb248bcc5a48c5bcf36aac17b5dbcb3 (patch) | |
tree | 4316097cf2c685e04dee37b01e3ea9d894694590 /src | |
parent | Fix argument name consistency (diff) | |
parent | catch badarg exceptions on invalid callback procs (diff) |
Merge branch 'mod_ping_no_kill' of https://github.com/fdie/ejabberd into 3
Diffstat (limited to 'src')
-rw-r--r-- | src/ejabberd_iq.erl | 6 | ||||
-rw-r--r-- | src/mod_ping.erl | 41 |
2 files changed, 26 insertions, 21 deletions
diff --git a/src/ejabberd_iq.erl b/src/ejabberd_iq.erl index 8c731e0a1..aeaffccde 100644 --- a/src/ejabberd_iq.erl +++ b/src/ejabberd_iq.erl @@ -173,4 +173,8 @@ calc_checksum(Data) -> callback(undefined, IQRes, Fun) -> Fun(IQRes); callback(Proc, IQRes, Ctx) -> - Proc ! {iq_reply, IQRes, Ctx}. + try + Proc ! {iq_reply, IQRes, Ctx} + catch _:badarg -> + ok + end. diff --git a/src/mod_ping.erl b/src/mod_ping.erl index ffdee2f01..25d2b60ed 100644 --- a/src/mod_ping.erl +++ b/src/mod_ping.erl @@ -122,30 +122,31 @@ handle_cast({start_ping, JID}, State) -> handle_cast({stop_ping, JID}, State) -> Timers = del_timer(JID, State#state.timers), {noreply, State#state{timers = Timers}}; -handle_cast({iq_reply, timeout, JID}, State) -> - ejabberd_hooks:run(user_ping_timeout, State#state.host, - [JID]), - Timers = case State#state.timeout_action of - kill -> - #jid{user = User, server = Server, - resource = Resource} = - JID, - case ejabberd_sm:get_session_pid(User, Server, Resource) - of - Pid when is_pid(Pid) -> ejabberd_c2s:close(Pid, ping_timeout); - _ -> ok - end, - del_timer(JID, State#state.timers); - _ -> - State#state.timers - end, - {noreply, State#state{timers = Timers}}; -handle_cast({iq_reply, #iq{}, _JID}, State) -> - {noreply, State}; handle_cast(Msg, State) -> ?WARNING_MSG("unexpected cast: ~p", [Msg]), {noreply, State}. +handle_info({iq_reply, #iq{type = error}, JID}, State) -> + handle_info({iq_reply, timeout, JID}, State); +handle_info({iq_reply, #iq{}, _JID}, State) -> + {noreply, State}; +handle_info({iq_reply, timeout, JID}, State) -> + Timers = del_timer(JID, State#state.timers), + ejabberd_hooks:run(user_ping_timeout, State#state.host, + [JID]), + case State#state.timeout_action of + kill -> + #jid{user = User, server = Server, + resource = Resource} = + JID, + case ejabberd_sm:get_session_pid(User, Server, Resource) + of + Pid when is_pid(Pid) -> ejabberd_c2s:close(Pid, ping_timeout); + _ -> ok + end; + _ -> ok + end, + {noreply, State#state{timers = Timers}}; handle_info({timeout, _TRef, {ping, JID}}, State) -> Host = State#state.host, From = jid:remove_resource(JID), |