Skip to content

Commit 1103bce

Browse files
committed
rabbit_ct_broker_helpers: Fix race condition with inet_tcp_proxy startup
Before this commit, for each node, we started inet_tcp_proxy and disconnected that node from others. I.e. inet_tcp_proxy was started on node 1, node 1 was disconnected, inet_tcp_proxy was started on node 2, node 2 was disconnected, and so on. There is a race condition in this scenario: when we disconnected node 1, either node 1 could reconnect to node 1, or node 2 could open the connection to node 1. In the second case, inet_tcp_proxy is still disabled on node 2, thus the connection would not go through the proxy. This meant that attempts to block the connection between nodes 1 and 2 would silently be ignored. To fix this race, we start inet_tcp_proxy on all nodes first, then we disconnect all nodes. I.e., inet_tcp_proxy is started on node 1, inet_tcp_proxy is started on node 2, node 1 is disconnected, node 2 is disconnected. [#146911969]
1 parent 45d33d4 commit 1103bce

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/rabbit_ct_broker_helpers.erl

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
set_partition_handling_mode_globally/2,
5656
enable_dist_proxy_manager/1,
5757
enable_dist_proxy/1,
58-
enable_dist_proxy_on_node/3,
58+
start_dist_proxy_on_node/2,
59+
disconnect_from_other_nodes/2,
5960
block_traffic_between/2,
6061
allow_traffic_between/2,
6162

@@ -615,20 +616,38 @@ enable_dist_proxy(Config) ->
615616
NodeConfigs = rabbit_ct_broker_helpers:get_node_configs(Config),
616617
Nodes = [?config(nodename, NodeConfig) || NodeConfig <- NodeConfigs],
617618
ManagerNode = node(),
619+
%% We first start the proxy process on all nodes, then we close the
620+
%% existing connection.
621+
%%
622+
%% If we do that in a single loop, i.e. start the proxy on node 1
623+
%% and disconnect it, then, start the proxy on node 2 and disconnect
624+
%% it, etc., there is a chance that the connection is reopened
625+
%% by a node where the proxy is still disabled. Therefore, that
626+
%% connection would bypass the proxy process even though we believe
627+
%% it to be enabled.
618628
ok = lists:foreach(
619629
fun(NodeConfig) ->
620630
ok = rabbit_ct_broker_helpers:rpc(Config,
621631
?config(nodename, NodeConfig),
622-
?MODULE, enable_dist_proxy_on_node,
623-
[NodeConfig, ManagerNode, Nodes])
632+
?MODULE, start_dist_proxy_on_node,
633+
[NodeConfig, ManagerNode])
634+
end, NodeConfigs),
635+
ok = lists:foreach(
636+
fun(NodeConfig) ->
637+
ok = rabbit_ct_broker_helpers:rpc(Config,
638+
?config(nodename, NodeConfig),
639+
?MODULE, disconnect_from_other_nodes,
640+
[NodeConfig, Nodes])
624641
end, NodeConfigs),
625642
Config.
626643

627-
enable_dist_proxy_on_node(NodeConfig, ManagerNode, Nodes) ->
628-
Nodename = ?config(nodename, NodeConfig),
644+
start_dist_proxy_on_node(NodeConfig, ManagerNode) ->
629645
DistPort = ?config(tcp_port_erlang_dist, NodeConfig),
630646
ProxyPort = ?config(tcp_port_erlang_dist_proxy, NodeConfig),
631-
ok = inet_tcp_proxy:start(ManagerNode, DistPort, ProxyPort),
647+
ok = inet_tcp_proxy:start(ManagerNode, DistPort, ProxyPort).
648+
649+
disconnect_from_other_nodes(NodeConfig, Nodes) ->
650+
Nodename = ?config(nodename, NodeConfig),
632651
ok = inet_tcp_proxy:reconnect(Nodes -- [Nodename]).
633652

634653
block_traffic_between(NodeA, NodeB) ->

0 commit comments

Comments
 (0)