Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry for erl_epmd:port_please #5331

Merged
merged 4 commits into from
Jul 26, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion deps/rabbit/src/rabbit_networking.erl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
-define(FIRST_TEST_BIND_PORT, 49152).

-define(ETS_TABLE, rabbit_listener_ets).
%% Number of re-try in case of no_epmd_port
%% it can happen when the DNS is not ready
%% for example, in Kubernetes during the start-up phase
-define(PORT_PLEASE_ATTEMPTS, 10).

%% Wait for retry when erl_epmd:port_please fails
%% See erl_epmd_port_please
-define(PORT_PLEASE_ATTEMPTS_WAIT, 20000).
Gsantomaggio marked this conversation as resolved.
Show resolved Hide resolved

%%----------------------------------------------------------------------------

Expand Down Expand Up @@ -400,7 +408,33 @@ tcp_listener_stopped_ets(L) ->
-spec record_distribution_listener() -> ok | no_return().

record_distribution_listener() ->
{Name, Host} = rabbit_nodes:parts(node()),
{Name, Host} = rabbit_nodes:parts(node()),
epmd_port_please(Name, Host).


-spec epmd_port_please(string(),string()) -> ok | no_return().

epmd_port_please(Name, Host) ->
epmd_port_please(Name, Host, ?PORT_PLEASE_ATTEMPTS).
%% erl_epmd:port_please could fail if the DNS is not ready yet
%% for example in Kubernetes. We retry a few times.
%% (PORT_PLEASE_ATTEMPTS * PORT_PLEASE_ATTEMPTS_WAIT)
-spec epmd_port_please(string(),string(), integer()) -> ok | no_return().
epmd_port_please(Name, Host, 0) ->
maybe_get_epmd_port(Name, Host);
epmd_port_please(Name, Host, RetriesLeft) ->
rabbit_log:debug("Getting epmd port node '~s', ~b retries left",
[Name, RetriesLeft]),
case catch maybe_get_epmd_port(Name, Host) of
ok -> ok;
{error, _} ->
timer:sleep(?PORT_PLEASE_ATTEMPTS_WAIT),
epmd_port_please(Name, Host, RetriesLeft - 1)
end.

-spec maybe_get_epmd_port(string(),string()) -> ok | no_return().

maybe_get_epmd_port(Name, Host) ->
case erl_epmd:port_please(list_to_atom(Name), Host, infinity) of
{port, Port, _Version} ->
IPAddress =
Expand All @@ -413,6 +447,7 @@ record_distribution_listener() ->
throw({error, no_epmd_port})
end.


-spec active_listeners() -> [rabbit_types:listener()].

active_listeners() ->
Expand Down