Skip to content

Commit

Permalink
Only copy local listeners when FF listener_records_in_ets is enabled
Browse files Browse the repository at this point in the history
The `rabbit_listener_ets` table normally only contains listener entries
for the local node. However after upgrading to 3.11.x and the
`listener_records_in_ets` feature flag is enabled, all entries were
copied to ETS from Mnesia, and the replicated Mnesia table contained
entries for all nodes in a multi-node cluster.

In this state `rabbit_networking:listener_of_protocol_ets/1` could crash
with a case clause when multiple rows match a protocol. This can happen
for example when the node is put in maintenance and the web_stomp plugin
is enabled which queries the ranch refs to close all client connections.
(rabbit_web_stomp_listener:close_all_client_connections)/1)

A simple restart of the node or app reinitializes the listeners and the
ETS table so this "corrupt" state is cleared.
  • Loading branch information
gomoripeti committed Jul 31, 2023
1 parent 68e82b5 commit 01c3e88
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion deps/rabbit/src/rabbit_core_ff.erl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ listener_records_in_ets_enable(#{feature_name := FeatureName}) ->
rabbit_listener, [{'$1',[],['$1']}]),
lists:foreach(
fun(Listener) ->
ets:insert(rabbit_listener_ets, Listener)
rabbit_networking:is_local_listener(Listener)
andalso ets:insert(rabbit_listener_ets, Listener)
end, Listeners)
end)
catch
Expand Down
6 changes: 6 additions & 0 deletions deps/rabbit/src/rabbit_networking.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

-export([ensure_listener_table_for_this_node/0]).

-export([is_local_listener/1]).

-deprecated([{force_connection_event_refresh, 1, eventually}]).

-export([
Expand Down Expand Up @@ -819,3 +821,7 @@ ipv6_status(TestPort) ->
ensure_listener_table_for_this_node() ->
_ = ets:new(?ETS_TABLE, [named_table, public, bag, {keypos, #listener.node}]),
ok.

%% Needed for migration when feature flag listener_records_in_ets is enabled
is_local_listener(#listener{node = Node}) ->
Node =:= node().

0 comments on commit 01c3e88

Please sign in to comment.