aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssl
diff options
context:
space:
mode:
authorZandra <[email protected]>2016-01-27 10:33:56 +0100
committerZandra <[email protected]>2016-01-27 10:33:56 +0100
commit8a9e1a85a372055a1e8c1dcceec0991b4740ad12 (patch)
treebd24bac1893a12d241806f827569665f51a527fe /lib/ssl
parent6945881b99aeadaf9ed4ec1f8c7811538cee1405 (diff)
parentc4e594710f0e822db06a277b0a763e02d73d6e24 (diff)
downloadotp-8a9e1a85a372055a1e8c1dcceec0991b4740ad12.tar.gz
otp-8a9e1a85a372055a1e8c1dcceec0991b4740ad12.tar.bz2
otp-8a9e1a85a372055a1e8c1dcceec0991b4740ad12.zip
Merge branch 'legoscia/tls_dist_wait_for_code_server' into maint
* legoscia/tls_dist_wait_for_code_server: TLS distribution: wait for code server OTP-13268
Diffstat (limited to 'lib/ssl')
-rw-r--r--lib/ssl/src/ssl_tls_dist_proxy.erl30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/ssl/src/ssl_tls_dist_proxy.erl b/lib/ssl/src/ssl_tls_dist_proxy.erl
index 3edd352891..080817d204 100644
--- a/lib/ssl/src/ssl_tls_dist_proxy.erl
+++ b/lib/ssl/src/ssl_tls_dist_proxy.erl
@@ -196,6 +196,7 @@ accept_loop(Proxy, world = Type, Listen, Extra) ->
case gen_tcp:accept(Listen) of
{ok, Socket} ->
Opts = get_ssl_options(server),
+ wait_for_code_server(),
case ssl:ssl_accept(Socket, Opts) of
{ok, SslSocket} ->
PairHandler =
@@ -217,6 +218,35 @@ accept_loop(Proxy, world = Type, Listen, Extra) ->
end,
accept_loop(Proxy, Type, Listen, Extra).
+wait_for_code_server() ->
+ %% This is an ugly hack. Upgrading a socket to TLS requires the
+ %% crypto module to be loaded. Loading the crypto module triggers
+ %% its on_load function, which calls code:priv_dir/1 to find the
+ %% directory where its NIF library is. However, distribution is
+ %% started earlier than the code server, so the code server is not
+ %% necessarily started yet, and code:priv_dir/1 might fail because
+ %% of that, if we receive an incoming connection on the
+ %% distribution port early enough.
+ %%
+ %% If the on_load function of a module fails, the module is
+ %% unloaded, and the function call that triggered loading it fails
+ %% with 'undef', which is rather confusing.
+ %%
+ %% Thus, the ssl_tls_dist_proxy process will terminate, and be
+ %% restarted by ssl_dist_sup. However, it won't have any memory
+ %% of being asked by net_kernel to listen for incoming
+ %% connections. Hence, the node will believe that it's open for
+ %% distribution, but it actually isn't.
+ %%
+ %% So let's avoid that by waiting for the code server to start.
+ case whereis(code_server) of
+ undefined ->
+ timer:sleep(10),
+ wait_for_code_server();
+ Pid when is_pid(Pid) ->
+ ok
+ end.
+
try_connect(Port) ->
case gen_tcp:connect({127,0,0,1}, Port, [{active, false}, {packet,?PPRE}, nodelay()]) of
R = {ok, _S} ->