Skip to content

Commit

Permalink
rabbit_peer_discovery: Fix non-tail-recursive query_node_props2()
Browse files Browse the repository at this point in the history
[Why]
This impacts what is reported by the catch because it caught exceptions
emitted by code supposedly called later. An example is the assert
in `query_node_props2/3` last clause.
  • Loading branch information
dumbbell committed Nov 25, 2024
1 parent 62f22a7 commit 4d4985f
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions deps/rabbit/src/rabbit_peer_discovery.erl
Original file line number Diff line number Diff line change
Expand Up @@ -596,30 +596,34 @@ query_node_props1([], [], NodesAndProps, ThisNode) ->
query_node_props2(NodesAndProps1, [], ThisNode).

query_node_props2([{Node, Members} | Rest], NodesAndProps, ThisNode) ->
try
erpc:call(
Node, logger, debug,
["Peer discovery: temporary hidden node '~ts' queries properties "
"from node '~ts'", [node(), Node]]),
StartTime = get_node_start_time(Node, microsecond),
IsReady = is_node_db_ready(Node, ThisNode),
NodeAndProps = {Node, Members, StartTime, IsReady},
NodesAndProps1 = [NodeAndProps | NodesAndProps],
query_node_props2(Rest, NodesAndProps1, ThisNode)
catch
_:Error:_ ->
%% If one of the erpc calls we use to get the start time fails,
%% there is something wrong with the remote node because it
%% doesn't depend on RabbitMQ. We exclude it from the discovered
%% nodes.
?LOG_DEBUG(
"Peer discovery: failed to query start time of node '~ts': "
"~0tp~n"
"Peer discovery: node '~ts' excluded from the discovered nodes",
[Node, Error, Node],
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
query_node_props2(Rest, NodesAndProps, ThisNode)
end;
NodesAndProps2 = try
erpc:call(
Node, logger, debug,
["Peer discovery: temporary hidden node '~ts' "
"queries properties from node '~ts'",
[node(), Node]]),
StartTime = get_node_start_time(Node, microsecond),
IsReady = is_node_db_ready(Node, ThisNode),
NodeAndProps = {Node, Members, StartTime, IsReady},
NodesAndProps1 = [NodeAndProps | NodesAndProps],
NodesAndProps1
catch
_:Error:_ ->
%% If one of the erpc calls we use to get the
%% start time fails, there is something wrong with
%% the remote node because it doesn't depend on
%% RabbitMQ. We exclude it from the discovered
%% nodes.
?LOG_DEBUG(
"Peer discovery: failed to query start time "
"+ DB readyness of node '~ts': ~0tp~n"
"Peer discovery: node '~ts' excluded from the "
"discovered nodes",
[Node, Error, Node],
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
NodesAndProps
end,
query_node_props2(Rest, NodesAndProps2, ThisNode);
query_node_props2([], NodesAndProps, _ThisNode) ->
NodesAndProps1 = lists:reverse(NodesAndProps),
NodesAndProps2 = sort_nodes_and_props(NodesAndProps1),
Expand Down

0 comments on commit 4d4985f

Please sign in to comment.