Skip to content

Commit 8c47b0f

Browse files
committed
rabbit_peer_discovery: Always execute teardown code after exception
[Why] We start a temporary hidden node, then ask it to execute some code, then stop it. But if there is an execution in between, we leave the temporary hidden node running. Likewise when we mess with the group leader: if the function executed after overriding the group leader temporarily raises an exception, the group leader becomes permanent and we may miss log messages. [How] We simply use a try/after block to ensure the temporary things are reverted at the end, regardless of the success or failure. Follow up to #9797. Submitted by: @lukebakken
1 parent 1d76825 commit 8c47b0f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

deps/rabbit/src/rabbit_peer_discovery.erl

+11-7
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,11 @@ query_node_props(Nodes) when Nodes =/= [] ->
387387
"discovered peers properties",
388388
[Peer],
389389
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
390-
Ret = erpc:call(Peer, ?MODULE, do_query_node_props, [Nodes]),
391-
peer:stop(Pid),
392-
Ret;
390+
try
391+
erpc:call(Peer, ?MODULE, do_query_node_props, [Nodes])
392+
after
393+
peer:stop(Pid)
394+
end;
393395
{error, _} = Error ->
394396
?LOG_ERROR(
395397
"Peer discovery: failed to start temporary hidden node to "
@@ -448,10 +450,12 @@ do_query_node_props(Nodes) when Nodes =/= [] ->
448450

449451
with_group_leader_proxy(ProxyGroupLeader, Fun) ->
450452
UpstreamGroupLeader = erlang:group_leader(),
451-
true = erlang:group_leader(ProxyGroupLeader, self()),
452-
Ret = Fun(),
453-
true = erlang:group_leader(UpstreamGroupLeader, self()),
454-
Ret.
453+
try
454+
true = erlang:group_leader(ProxyGroupLeader, self()),
455+
Fun()
456+
after
457+
true = erlang:group_leader(UpstreamGroupLeader, self())
458+
end.
455459

456460
group_leader_proxy(Parent, UpstreamGroupLeader) ->
457461
receive

0 commit comments

Comments
 (0)