diff --git a/ChangeLog b/ChangeLog index 99f7f0c7a..3cc8e13f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-07-18 Mickael Remond + + * src/ejabberd_s2s_out.erl: Make s2s connections more robust + * src/ejabberd_s2s.erl: Likewise + 2007-07-17 Mickael Remond * src/mod_configure.erl: Bugfix: Show only virtual host users diff --git a/src/ejabberd_s2s.erl b/src/ejabberd_s2s.erl index 76fc2d39f..2c73daa36 100644 --- a/src/ejabberd_s2s.erl +++ b/src/ejabberd_s2s.erl @@ -61,12 +61,17 @@ remove_connection(FromTo) -> mnesia:transaction(F). remove_connection(FromTo, Pid, Key) -> - F = fun() -> - mnesia:delete_object(#s2s{fromto = FromTo, - pid = Pid, - key = Key}) - end, - mnesia:transaction(F). + case catch mnesia:dirty_read(s2s, FromTo) of + [#s2s{pid = Pid, key = Key}] -> + F = fun() -> + mnesia:delete_object(#s2s{fromto = FromTo, + pid = Pid, + key = Key}) + end, + mnesia:transaction(F); + _ -> + ok + end. have_connection(FromTo) -> case catch mnesia:dirty_read(s2s, FromTo) of @@ -262,7 +267,7 @@ find_connection(From, To) -> {atomic, Pid} -> ejabberd_s2s_out:start_connection(Pid); _ -> - ok + ejabberd_s2s_out:stop_connection(Pid) end, TRes end; diff --git a/src/ejabberd_s2s_out.erl b/src/ejabberd_s2s_out.erl index 62a952e99..0effa91e3 100644 --- a/src/ejabberd_s2s_out.erl +++ b/src/ejabberd_s2s_out.erl @@ -13,7 +13,8 @@ %% External exports -export([start/3, start_link/3, - start_connection/1]). + start_connection/1, + stop_connection/1]). %% gen_fsm callbacks -export([init/1, @@ -89,6 +90,9 @@ start_link(From, Host, Type) -> start_connection(Pid) -> gen_fsm:send_event(Pid, init). +stop_connection(Pid) -> + gen_fsm:send_event(Pid, stop). + %%%---------------------------------------------------------------------- %%% Callback functions from gen_fsm %%%---------------------------------------------------------------------- @@ -175,6 +179,8 @@ open_socket(init, StateData) -> bounce_messages(Error), {stop, normal, StateData} end; +open_socket(stop, StateData) -> + {stop, normal, StateData}; open_socket(_, StateData) -> {next_state, open_socket, StateData}.