Skip to content

Commit 2b9d1d1

Browse files
Merge pull request #2722 from rabbitmq/rabbitmq_epmd_wait
Retry epmd name lookups N times during pre-launch
1 parent 3470ffb commit 2b9d1d1

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

deps/rabbit_common/src/rabbit_nodes_common.erl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
-module(rabbit_nodes_common).
99

10-
-define(EPMD_TIMEOUT, 30000).
10+
-define(EPMD_OPERATION_TIMEOUT, 6000).
11+
-define(NAME_LOOKUP_ATTEMPTS, 10).
1112
-define(TCP_DIAGNOSTIC_TIMEOUT, 5000).
1213
-define(ERROR_LOGGER_HANDLER, rabbit_error_logger_handler).
1314

@@ -27,6 +28,9 @@
2728

2829
-spec names(string()) ->
2930
rabbit_types:ok_or_error2([{string(), integer()}], term()).
31+
-spec epmd_names(string()) ->
32+
rabbit_types:ok_or_error2([{string(), integer()}], term()).
33+
3034
-spec diagnostics([node()]) -> string().
3135
-spec cookie_hash() -> string().
3236

@@ -36,12 +40,29 @@
3640
%% Therefore we disable this specific warning.
3741
-dialyzer({nowarn_function, diagnostics_node/1}).
3842

43+
%% In same case the hostname resolution can take a moment.
44+
%% In K8s for example *.nodes.default needs some second.
45+
3946
names(Hostname) ->
47+
names(Hostname, ?NAME_LOOKUP_ATTEMPTS).
48+
49+
names(Hostname, 0) ->
50+
epmd_names(Hostname);
51+
names(Hostname, RetriesLeft) ->
52+
rabbit_log:debug("Getting epmd names for hostname '~s', ~b retries left",
53+
[Hostname, RetriesLeft]),
54+
case catch epmd_names(Hostname) of
55+
{ok, R } -> {ok, R};
56+
{error, _} ->
57+
names(Hostname, RetriesLeft - 1)
58+
end.
59+
60+
epmd_names(Hostname) ->
4061
Self = self(),
4162
Ref = make_ref(),
4263
{Pid, MRef} = spawn_monitor(
4364
fun () -> Self ! {Ref, net_adm:names(Hostname)} end),
44-
_ = timer:exit_after(?EPMD_TIMEOUT, Pid, timeout),
65+
_ = timer:exit_after(?EPMD_OPERATION_TIMEOUT, Pid, timeout),
4566
receive
4667
{Ref, Names} -> erlang:demonitor(MRef, [flush]),
4768
Names;

0 commit comments

Comments
 (0)