summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngela Anderton Andin <ingela@erlang.org>2021-02-11 09:06:55 +0100
committerIngela Anderton Andin <ingela@erlang.org>2021-02-11 09:44:57 +0100
commita264d73ed3fd6d8cd5fea07b7edb338a61e8d847 (patch)
treed7095b30aba0159ce42af4cb353ecd0eabc268c9
parent74d045d62e283948247e03a93d22171802997804 (diff)
downloaderlang-a264d73ed3fd6d8cd5fea07b7edb338a61e8d847.tar.gz
ssl: Avoid race when two upgrade servers are started close to each other
-rw-r--r--lib/ssl/src/ssl_upgrade_server_session_cache_sup.erl19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/ssl/src/ssl_upgrade_server_session_cache_sup.erl b/lib/ssl/src/ssl_upgrade_server_session_cache_sup.erl
index 3e1f1a10cf..936ffcc0ac 100644
--- a/lib/ssl/src/ssl_upgrade_server_session_cache_sup.erl
+++ b/lib/ssl/src/ssl_upgrade_server_session_cache_sup.erl
@@ -50,12 +50,21 @@ start_child(Type) ->
Children = supervisor:count_children(SupName),
Workers = proplists:get_value(workers, Children),
case Workers of
- 0 ->
- supervisor:start_child(SupName, [ssl_unknown_listener | ssl_config:pre_1_3_session_opts()]);
- 1 ->
- [{_,Child,_, _}] = supervisor:which_children(SupName),
+ 0 ->
+ %% In case two upgrade servers are started very close to each other
+ %% only one will be able to grab the local name and we will use
+ %% that process for handling pre TLS-1.3 sessions for
+ %% servers with to us unknown listeners.
+ case supervisor:start_child(SupName, [ssl_unknown_listener | ssl_config:pre_1_3_session_opts()]) of
+ {error, {already_started, Child}} ->
+ {ok, Child};
+ {ok, _} = Return ->
+ Return
+ end;
+ 1 ->
+ [{_,Child,_, _}] = supervisor:which_children(SupName),
{ok, Child}
- end.
+ end.
%%%=========================================================================
%%% Supervisor callback