From 72f6835feb8566c6a996c904824654f3f8eee436 Mon Sep 17 00:00:00 2001 From: Evgeny Khramtsov Date: Tue, 29 Oct 2019 13:36:40 +0300 Subject: [PATCH] Fix race condition in Redis/SQL supervisors startup --- src/ejabberd_redis_sup.erl | 5 ++++- src/ejabberd_sql_sup.erl | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ejabberd_redis_sup.erl b/src/ejabberd_redis_sup.erl index 8605d24e5..7bba0882a 100644 --- a/src/ejabberd_redis_sup.erl +++ b/src/ejabberd_redis_sup.erl @@ -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 diff --git a/src/ejabberd_sql_sup.erl b/src/ejabberd_sql_sup.erl index 731612e53..074080f5f 100644 --- a/src/ejabberd_sql_sup.erl +++ b/src/ejabberd_sql_sup.erl @@ -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