25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-30 16:36:29 +01:00

mod_push_keepalive: Delay 'wake_on_start'

Delay the 'wake_on_start' notifications until ejabberd is fully
initialized.  This makes sure no s2s connections are initiated before
certificates are loaded.

Many thanks to Friedrich Altheide for reporting the issue.
This commit is contained in:
Holger Weiss 2023-08-08 20:17:10 +02:00
parent a9347cd248
commit 26ed6539ba

View File

@ -32,8 +32,9 @@
-export([start/2, stop/1, reload/3, mod_opt_type/1, mod_options/1, depends/2]). -export([start/2, stop/1, reload/3, mod_opt_type/1, mod_options/1, depends/2]).
-export([mod_doc/0]). -export([mod_doc/0]).
%% ejabberd_hooks callbacks. %% ejabberd_hooks callbacks.
-export([c2s_session_pending/1, c2s_session_resumed/1, c2s_copy_session/2, -export([ejabberd_started/0, c2s_session_pending/1, c2s_session_resumed/1,
c2s_handle_cast/2, c2s_handle_info/2, c2s_stanza/3]). c2s_copy_session/2, c2s_handle_cast/2, c2s_handle_info/2,
c2s_stanza/3]).
-include("logger.hrl"). -include("logger.hrl").
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
@ -47,13 +48,7 @@
%% gen_mod callbacks. %% gen_mod callbacks.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec start(binary(), gen_mod:opts()) -> ok. -spec start(binary(), gen_mod:opts()) -> ok.
start(Host, Opts) -> start(Host, _Opts) ->
case mod_push_keepalive_opt:wake_on_start(Opts) of
true ->
wake_all(Host);
false ->
ok
end,
register_hooks(Host). register_hooks(Host).
-spec stop(binary()) -> ok. -spec stop(binary()) -> ok.
@ -61,14 +56,8 @@ stop(Host) ->
unregister_hooks(Host). unregister_hooks(Host).
-spec reload(binary(), gen_mod:opts(), gen_mod:opts()) -> ok. -spec reload(binary(), gen_mod:opts(), gen_mod:opts()) -> ok.
reload(Host, NewOpts, OldOpts) -> reload(_Host, _NewOpts, _OldOpts) ->
case {mod_push_keepalive_opt:wake_on_start(NewOpts), ok.
mod_push_keepalive_opt:wake_on_start(OldOpts)} of
{true, false} ->
wake_all(Host);
_ ->
ok
end.
-spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}]. -spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}].
depends(_Host, _Opts) -> depends(_Host, _Opts) ->
@ -146,7 +135,10 @@ register_hooks(Host) ->
ejabberd_hooks:add(c2s_handle_info, Host, ?MODULE, ejabberd_hooks:add(c2s_handle_info, Host, ?MODULE,
c2s_handle_info, 50), c2s_handle_info, 50),
ejabberd_hooks:add(c2s_handle_send, Host, ?MODULE, ejabberd_hooks:add(c2s_handle_send, Host, ?MODULE,
c2s_stanza, 50). c2s_stanza, 50),
% Wait for ejabberd_pkix before running our ejabberd_started/0, so that we
% don't initiate s2s connections before certificates are loaded:
ejabberd_hooks:add(ejabberd_started, ?MODULE, ejabberd_started, 90).
-spec unregister_hooks(binary()) -> ok. -spec unregister_hooks(binary()) -> ok.
unregister_hooks(Host) -> unregister_hooks(Host) ->
@ -161,7 +153,14 @@ unregister_hooks(Host) ->
ejabberd_hooks:delete(c2s_handle_info, Host, ?MODULE, ejabberd_hooks:delete(c2s_handle_info, Host, ?MODULE,
c2s_handle_info, 50), c2s_handle_info, 50),
ejabberd_hooks:delete(c2s_handle_send, Host, ?MODULE, ejabberd_hooks:delete(c2s_handle_send, Host, ?MODULE,
c2s_stanza, 50). c2s_stanza, 50),
case gen_mod:is_loaded_elsewhere(Host, ?MODULE) of
false ->
ejabberd_hooks:delete(
ejabberd_started, ?MODULE, ejabberd_started, 90);
true ->
ok
end.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Hook callbacks. %% Hook callbacks.
@ -233,6 +232,12 @@ c2s_handle_info(#{push_enabled := true, mgmt_state := pending,
c2s_handle_info(State, _) -> c2s_handle_info(State, _) ->
State. State.
-spec ejabberd_started() -> ok.
ejabberd_started() ->
[wake_all(Host) || Host <- ejabberd_config:get_option(hosts),
mod_push_keepalive_opt:wake_on_start(Host)],
ok.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Internal functions. %% Internal functions.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------