25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

Gracefully close inbound s2s connections

This commit is contained in:
Evgeny Khramtsov 2019-07-10 12:15:58 +03:00
parent 722864666d
commit 5700089187

View File

@ -289,6 +289,7 @@ handle_info(Info, State) ->
terminate(_Reason, _State) -> terminate(_Reason, _State) ->
ejabberd_commands:unregister_commands(get_commands_spec()), ejabberd_commands:unregister_commands(get_commands_spec()),
stop_s2s_connections(stream_error()),
lists:foreach(fun host_down/1, ejabberd_option:hosts()), lists:foreach(fun host_down/1, ejabberd_option:hosts()),
ejabberd_hooks:delete(host_up, ?MODULE, host_up, 50), ejabberd_hooks:delete(host_up, ?MODULE, host_up, 50),
ejabberd_hooks:delete(host_down, ?MODULE, host_down, 60). ejabberd_hooks:delete(host_down, ?MODULE, host_down, 60).
@ -306,11 +307,12 @@ host_up(Host) ->
-spec host_down(binary()) -> ok. -spec host_down(binary()) -> ok.
host_down(Host) -> host_down(Host) ->
Err = stream_error(),
lists:foreach( lists:foreach(
fun(#s2s{fromto = {From, _}, pid = Pid}) when node(Pid) == node() -> fun(#s2s{fromto = {From, _}, pid = Pid}) when node(Pid) == node() ->
case ejabberd_router:host_of_route(From) of case ejabberd_router:host_of_route(From) of
Host -> Host ->
ejabberd_s2s_out:send(Pid, xmpp:serr_system_shutdown()), ejabberd_s2s_out:send(Pid, Err),
ejabberd_s2s_out:stop(Pid); ejabberd_s2s_out:stop(Pid);
_ -> _ ->
ok ok
@ -538,17 +540,32 @@ supervisor_count(Supervisor) ->
-spec stop_s2s_connections() -> ok. -spec stop_s2s_connections() -> ok.
stop_s2s_connections() -> stop_s2s_connections() ->
stop_s2s_connections(xmpp:serr_reset()).
-spec stop_s2s_connections(stream_error()) -> ok.
stop_s2s_connections(Err) ->
lists:foreach( lists:foreach(
fun({_Id, Pid, _Type, _Module}) -> fun({_Id, Pid, _Type, _Module}) ->
ejabberd_s2s_in:send(Pid, Err),
ejabberd_s2s_in:stop(Pid),
supervisor:terminate_child(ejabberd_s2s_in_sup, Pid) supervisor:terminate_child(ejabberd_s2s_in_sup, Pid)
end, supervisor:which_children(ejabberd_s2s_in_sup)), end, supervisor:which_children(ejabberd_s2s_in_sup)),
lists:foreach( lists:foreach(
fun({_Id, Pid, _Type, _Module}) -> fun({_Id, Pid, _Type, _Module}) ->
ejabberd_s2s_out:send(Pid, Err),
ejabberd_s2s_out:stop(Pid),
supervisor:terminate_child(ejabberd_s2s_out_sup, Pid) supervisor:terminate_child(ejabberd_s2s_out_sup, Pid)
end, supervisor:which_children(ejabberd_s2s_out_sup)), end, supervisor:which_children(ejabberd_s2s_out_sup)),
_ = mnesia:clear_table(s2s), _ = mnesia:clear_table(s2s),
ok. ok.
-spec stream_error() -> stream_error().
stream_error() ->
case ejabberd_cluster:get_nodes() of
[Node] when Node == node() -> xmpp:serr_system_shutdown();
_ -> xmpp:serr_reset()
end.
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% Update Mnesia tables %%% Update Mnesia tables