Skip to content

rabbit_{connection,channel}_tracking: Fix race condition in list() (backport #3324) #3326

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

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion deps/rabbit/src/rabbit_channel_tracking.erl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,18 @@ list() ->
lists:foldl(
fun (Node, Acc) ->
Tab = tracked_channel_table_name_for(Node),
Acc ++ mnesia:dirty_match_object(Tab, #tracked_channel{_ = '_'})
try
Acc ++
mnesia:dirty_match_object(Tab, #tracked_channel{_ = '_'})
catch
exit:{aborted, {no_exists, [Tab, _]}} ->
%% The table might not exist yet (or is already gone)
%% between the time rabbit_nodes:all_running() runs and
%% returns a specific node, and
%% mnesia:dirty_match_object() is called for that node's
%% table.
Acc
end
end, [], rabbit_nodes:all_running()).

-spec list_of_user(rabbit_types:username()) -> [rabbit_types:tracked_channel()].
Expand Down
16 changes: 15 additions & 1 deletion deps/rabbit/src/rabbit_connection_tracking.erl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,18 @@ list() ->
lists:foldl(
fun (Node, Acc) ->
Tab = tracked_connection_table_name_for(Node),
Acc ++ mnesia:dirty_match_object(Tab, #tracked_connection{_ = '_'})
try
Acc ++
mnesia:dirty_match_object(Tab, #tracked_connection{_ = '_'})
catch
exit:{aborted, {no_exists, [Tab, _]}} ->
%% The table might not exist yet (or is already gone)
%% between the time rabbit_nodes:all_running() runs and
%% returns a specific node, and
%% mnesia:dirty_match_object() is called for that node's
%% table.
Acc
end
end, [], rabbit_nodes:all_running()).

-spec count() -> non_neg_integer().
Expand All @@ -360,6 +371,9 @@ count() ->
lists:foldl(
fun (Node, Acc) ->
Tab = tracked_connection_table_name_for(Node),
%% mnesia:table_info() returns 0 if the table doesn't exist. We
%% don't need the same kind of protection as the list() function
%% above.
Acc + mnesia:table_info(Tab, size)
end, 0, rabbit_nodes:all_running()).

Expand Down