Skip to content

Commit 8425afa

Browse files
committed
rabbit_peer_discovery: Pass inetrc config file to temporary hidden node
[Why] As shown in #10728, in an IPv6-only environment, `kernel` name resolution must be configured through an inetrc file. The temporary hidden node must be configured exactly like the main node (and all nodes in the cluster in fact) to allow communication. Thus we must pass the same inetrc file to that temporary hidden node. This wasn’t the case before this patch. [How] We query the main node’s kernel to see if there is any inetrc file set and we use the same on the temporary hidden node’s command line. While here, extract the handling of the `proto_dist` module from the TLS code. This parameter may be used outside of TLS like this IPv6-only environment. V2: Accept `inetrc` filenames as atoms, not only lists. `kernel` seems to accept them. This makes a better user experience for users used to Bourne shell quoting not knowing that single quotes have a special meaning in Erlang. Fixes #10728.
1 parent 54f5ab5 commit 8425afa

File tree

1 file changed

+48
-28
lines changed

1 file changed

+48
-28
lines changed

deps/rabbit/src/rabbit_peer_discovery.erl

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
group_leader_proxy/2]).
3131

3232
-ifdef(TEST).
33-
-export([sort_nodes_and_props/1,
33+
-export([query_node_props/1,
34+
sort_nodes_and_props/1,
3435
join_selected_node/3]).
3536
-endif.
3637

@@ -388,16 +389,18 @@ query_node_props(Nodes) when Nodes =/= [] ->
388389
_ ->
389390
VMArgs1
390391
end,
391-
VMArgs3 = maybe_add_tls_arguments(VMArgs2),
392+
VMArgs3 = maybe_add_proto_dist_arguments(VMArgs2),
393+
VMArgs4 = maybe_add_inetrc_arguments(VMArgs3),
394+
VMArgs5 = maybe_add_tls_arguments(VMArgs4),
392395
PeerStartArg = case Context of
393396
#{nodename_type := longnames} ->
394397
#{name => PeerName,
395398
host => Suffix,
396399
longnames => true,
397-
args => VMArgs3};
400+
args => VMArgs5};
398401
_ ->
399402
#{name => PeerName,
400-
args => VMArgs3}
403+
args => VMArgs5}
401404
end,
402405
?LOG_DEBUG("Peer discovery: peer node arguments: ~tp",
403406
[PeerStartArg]),
@@ -423,27 +426,40 @@ query_node_props(Nodes) when Nodes =/= [] ->
423426
query_node_props([]) ->
424427
[].
425428

426-
maybe_add_tls_arguments(VMArgs0) ->
429+
maybe_add_proto_dist_arguments(VMArgs) ->
427430
case init:get_argument(proto_dist) of
428-
{ok, [["inet_tls"]]} ->
429-
add_tls_arguments(inet_tls, VMArgs0);
430-
{ok, [["inet6_tls"]]} ->
431-
add_tls_arguments(inet6_tls, VMArgs0);
431+
{ok, [[Val]]} ->
432+
%% See net_kernel.erl / protocol_childspecs/1.
433+
Mod = list_to_existing_atom(Val ++ "_dist"),
434+
ModDir = filename:dirname(code:which(Mod)),
435+
["-proto_dist", Val, "-pa", ModDir | VMArgs];
432436
_ ->
433-
VMArgs0
437+
VMArgs
434438
end.
435439

436-
add_tls_arguments(InetDistModule, VMArgs0) ->
437-
VMArgs1 = case InetDistModule of
438-
inet_tls ->
439-
ProtoDistArg = ["-proto_dist", "inet_tls" | VMArgs0],
440-
["-pa", filename:dirname(code:which(inet_tls_dist))
441-
| ProtoDistArg];
442-
inet6_tls ->
443-
ProtoDistArg = ["-proto_dist", "inet6_tls" | VMArgs0],
444-
["-pa", filename:dirname(code:which(inet6_tls_dist))
445-
| ProtoDistArg]
446-
end,
440+
maybe_add_inetrc_arguments(VMArgs) ->
441+
%% If an inetrc file is configured, we need to use it for the temporary
442+
%% hidden node too.
443+
case application:get_env(kernel, inetrc) of
444+
{ok, Val} ->
445+
maybe_add_inetrc_arguments1(VMArgs, Val);
446+
undefined ->
447+
case os:getenv("ERL_INETRC") of
448+
Val when is_list(Val) ->
449+
maybe_add_inetrc_arguments1(VMArgs, Val);
450+
false ->
451+
VMArgs
452+
end
453+
end.
454+
455+
maybe_add_inetrc_arguments1(VMArgs, Val) ->
456+
%% The filename argument must be passed as a quoted string so that the
457+
%% command line is correctly parsed as an Erlang string by the temporary
458+
%% hidden node.
459+
ValString = rabbit_misc:format("~0p", [Val]),
460+
["-kernel", "inetrc", ValString | VMArgs].
461+
462+
maybe_add_tls_arguments(VMArgs) ->
447463
%% In the next case, RabbitMQ has been configured with additional Erlang VM
448464
%% arguments such as this:
449465
%%
@@ -494,14 +510,14 @@ add_tls_arguments(InetDistModule, VMArgs0) ->
494510
%% "/usr/local/lib/erlang/lib/ssl-11.0.3/ebin",
495511
%% "-proto_dist","inet_tls","-boot",
496512
%% "no_dot_erlang","-hidden"],
497-
VMArgs2 = case init:get_argument(ssl_dist_opt) of
513+
VMArgs1 = case init:get_argument(ssl_dist_opt) of
498514
{ok, SslDistOpts0} ->
499515
SslDistOpts1 = [["-ssl_dist_opt" | SslDistOpt]
500516
|| SslDistOpt <- SslDistOpts0],
501517
SslDistOpts2 = lists:concat(SslDistOpts1),
502-
SslDistOpts2 ++ VMArgs1;
518+
SslDistOpts2 ++ VMArgs;
503519
_ ->
504-
VMArgs1
520+
VMArgs
505521
end,
506522
%% In the next case, RabbitMQ has been configured with additional Erlang VM
507523
%% arguments such as this:
@@ -511,13 +527,13 @@ add_tls_arguments(InetDistModule, VMArgs0) ->
511527
%%
512528
%% This code adds the `ssl_dist_optfile' argument to the peer node's
513529
%% argument list.
514-
VMArgs3 = case init:get_argument(ssl_dist_optfile) of
530+
VMArgs2 = case init:get_argument(ssl_dist_optfile) of
515531
{ok, [[SslDistOptfileArg]]} ->
516-
["-ssl_dist_optfile", SslDistOptfileArg | VMArgs2];
532+
["-ssl_dist_optfile", SslDistOptfileArg | VMArgs1];
517533
_ ->
518-
VMArgs2
534+
VMArgs1
519535
end,
520-
VMArgs3.
536+
VMArgs2.
521537

522538
do_query_node_props(Nodes) when Nodes =/= [] ->
523539
%% Make sure all log messages are forwarded from this temporary hidden
@@ -608,6 +624,10 @@ query_node_props1([], [], NodesAndProps, ProxyGroupLeader) ->
608624

609625
query_node_props2([{Node, Members} | Rest], NodesAndProps, ProxyGroupLeader) ->
610626
try
627+
erpc:call(
628+
Node, logger, debug,
629+
["Peer discovery: temporary hidden node '~ts' queries properties "
630+
"from node '~ts'", [node(), Node]]),
611631
StartTime = get_node_start_time(Node, microsecond, ProxyGroupLeader),
612632
IsReady = is_node_db_ready(Node, ProxyGroupLeader),
613633
NodeAndProps = {Node, Members, StartTime, IsReady},

0 commit comments

Comments
 (0)