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

Respect -proto_dist flag when specified multiple times #8672

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all 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
36 changes: 23 additions & 13 deletions lib/kernel/src/net_kernel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ in the Erlang Reference Manual.
-type connection_type() :: normal | hidden.

-include("net_address.hrl").
-include_lib("kernel/include/logger.hrl").

%% Relaxed typing to allow ets:select without Dialyzer complains.
-record(connection, {
Expand Down Expand Up @@ -2399,12 +2400,8 @@ split_node(Name) ->
%%
-doc false.
protocol_childspecs() ->
case init:get_argument(proto_dist) of
{ok, [Protos]} ->
protocol_childspecs(Protos);
_ ->
protocol_childspecs(["inet_tcp"])
end.
Protos = proto_dist_argument(),
protocol_childspecs(Protos).

protocol_childspecs([]) ->
[];
Expand Down Expand Up @@ -2456,17 +2453,31 @@ hidden_argument() ->
false
end.

%%%
%%% -proto_dist command line argument
%%%

proto_dist_argument() ->
case init:get_argument(proto_dist) of
{ok, [Protos | Rest]} ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidenote: similar functions above do not have that warning.

A follow up question: is there a reason we process proto_dist as a list, instead of getting the first item? In other words, is there a case where the user would pass -proto_dist [proto1, proto2]. The docs say -proto_dist Proto, indicating a single value is expected.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, not all functions have that warning, nor do many other places elsewhere in the codebase that uses init:get_argument/1 (most seem to either ignore the flag or grab the first argument, both of them silently). It's rather inconsistent unfortunately, but there's nothing wrong with fixing it as we go.

As for processing as a list the intent seems to be supporting multiple protocols at the same time, but as you noted we haven't documented that anywhere so it's not supported.

case Rest of
[] ->
ok;
_ ->
?LOG_WARNING("Multiple -proto_dist given to erl, using the first, ~p", [Protos])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: the warning shows up twice, since we read the value in two places.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine. :-)

end,
Protos;
_ ->
["inet_tcp"]
end.

%%
%% Start all protocols
%%

start_protos(Node, CleanHalt, Listen) ->
case init:get_argument(proto_dist) of
{ok, [Protos]} ->
start_protos(Node, Protos, CleanHalt, Listen);
_ ->
start_protos(Node, ["inet_tcp"], CleanHalt, Listen)
end.
Protos = proto_dist_argument(),
start_protos(Node, Protos, CleanHalt, Listen).

start_protos(Node, Ps, CleanHalt, Listen) ->
Listeners = case Listen of
Expand Down Expand Up @@ -3011,4 +3022,3 @@ opts_node(Op, Node, Opts, From, #state{req_map = ReqMap0} = S0) ->
_ ->
async_reply({reply, {error, noconnection}, S0}, From)
end.

Loading