Fix race condition in Redis/SQL supervisors startup

This commit is contained in:
Evgeny Khramtsov 2019-10-29 13:36:40 +03:00
parent 86c4f76c51
commit 72f6835feb
2 changed files with 8 additions and 2 deletions

View File

@ -45,7 +45,10 @@ start() ->
permanent, infinity, supervisor, [?MODULE]},
case supervisor:start_child(ejabberd_db_sup, Spec) of
{ok, _} -> ok;
{error, {already_started, _}} -> ok;
{error, {already_started, Pid}} ->
%% Wait for the supervisor to fully start
_ = supervisor:count_children(Pid),
ok;
{error, Why} = Err ->
?ERROR_MSG("Failed to start ~ts: ~p", [?MODULE, Why]),
Err

View File

@ -52,7 +52,10 @@ start(Host) ->
modules => [?MODULE]},
case supervisor:start_child(ejabberd_db_sup, Spec) of
{ok, _} -> ok;
{error, {already_started, _}} -> ok;
{error, {already_started, Pid}} ->
%% Wait for the supervisor to fully start
_ = supervisor:count_children(Pid),
ok;
{error, Why} = Err ->
?ERROR_MSG("Failed to start ~ts: ~p", [?MODULE, Why]),
Err