|
7 | 7 |
|
8 | 8 | -module(rabbit_nodes_common). |
9 | 9 |
|
10 | | --define(EPMD_TIMEOUT, 30000). |
| 10 | +-define(EPMD_OPERATION_TIMEOUT, 6000). |
| 11 | +-define(NAME_LOOKUP_ATTEMPTS, 10). |
11 | 12 | -define(TCP_DIAGNOSTIC_TIMEOUT, 5000). |
12 | 13 | -define(ERROR_LOGGER_HANDLER, rabbit_error_logger_handler). |
13 | 14 |
|
|
27 | 28 |
|
28 | 29 | -spec names(string()) -> |
29 | 30 | rabbit_types:ok_or_error2([{string(), integer()}], term()). |
| 31 | +-spec epmd_names(string()) -> |
| 32 | + rabbit_types:ok_or_error2([{string(), integer()}], term()). |
| 33 | + |
30 | 34 | -spec diagnostics([node()]) -> string(). |
31 | 35 | -spec cookie_hash() -> string(). |
32 | 36 |
|
|
36 | 40 | %% Therefore we disable this specific warning. |
37 | 41 | -dialyzer({nowarn_function, diagnostics_node/1}). |
38 | 42 |
|
| 43 | +%% In same case the hostname resolution can take a moment. |
| 44 | +%% In K8s for example *.nodes.default needs some second. |
| 45 | + |
39 | 46 | 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) -> |
40 | 61 | Self = self(), |
41 | 62 | Ref = make_ref(), |
42 | 63 | {Pid, MRef} = spawn_monitor( |
43 | 64 | 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), |
45 | 66 | receive |
46 | 67 | {Ref, Names} -> erlang:demonitor(MRef, [flush]), |
47 | 68 | Names; |
|
0 commit comments