Skip to content

Commit 4169531

Browse files
Merge pull request #3324 from rabbitmq/fix-race-condition-in-connection-channel-tracking-list-function
rabbit_{connection,channel}_tracking: Fix race condition in list()
2 parents 074a567 + 0b1942b commit 4169531

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

deps/rabbit/src/rabbit_channel_tracking.erl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,18 @@ list() ->
179179
lists:foldl(
180180
fun (Node, Acc) ->
181181
Tab = tracked_channel_table_name_for(Node),
182-
Acc ++ mnesia:dirty_match_object(Tab, #tracked_channel{_ = '_'})
182+
try
183+
Acc ++
184+
mnesia:dirty_match_object(Tab, #tracked_channel{_ = '_'})
185+
catch
186+
exit:{aborted, {no_exists, [Tab, _]}} ->
187+
%% The table might not exist yet (or is already gone)
188+
%% between the time rabbit_nodes:all_running() runs and
189+
%% returns a specific node, and
190+
%% mnesia:dirty_match_object() is called for that node's
191+
%% table.
192+
Acc
193+
end
183194
end, [], rabbit_nodes:all_running()).
184195

185196
-spec list_of_user(rabbit_types:username()) -> [rabbit_types:tracked_channel()].

deps/rabbit/src/rabbit_connection_tracking.erl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,18 @@ list() ->
351351
lists:foldl(
352352
fun (Node, Acc) ->
353353
Tab = tracked_connection_table_name_for(Node),
354-
Acc ++ mnesia:dirty_match_object(Tab, #tracked_connection{_ = '_'})
354+
try
355+
Acc ++
356+
mnesia:dirty_match_object(Tab, #tracked_connection{_ = '_'})
357+
catch
358+
exit:{aborted, {no_exists, [Tab, _]}} ->
359+
%% The table might not exist yet (or is already gone)
360+
%% between the time rabbit_nodes:all_running() runs and
361+
%% returns a specific node, and
362+
%% mnesia:dirty_match_object() is called for that node's
363+
%% table.
364+
Acc
365+
end
355366
end, [], rabbit_nodes:all_running()).
356367

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

0 commit comments

Comments
 (0)