Skip to content

Commit 8274853

Browse files
Merge pull request #1111 from rabbitmq/rabbitmq-top-20
Initialize core stats before any gen_server2 is started
2 parents 6f9ce65 + 1d9a24e commit 8274853

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/rabbit.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
[{description, "core metrics storage"},
9090
{mfa, {rabbit_sup, start_child,
9191
[rabbit_metrics]}},
92-
{requires, external_infrastructure},
93-
{enables, kernel_ready}]}).
92+
{requires, pre_boot},
93+
{enables, external_infrastructure}]}).
9494

9595
-rabbit_boot_step({rabbit_event,
9696
[{description, "statistics event manager"},

test/priority_queue_SUITE.erl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ groups() ->
4444
resume,
4545
simple_order,
4646
straight_through,
47-
invoke
47+
invoke,
48+
gen_server2_stats
4849
]},
4950
{cluster_size_3, [], [
5051
mirror_queue_auto_ack,
@@ -213,6 +214,29 @@ invoke(Config) ->
213214
rabbit_ct_client_helpers:close_connection(Conn),
214215
passed.
215216

217+
218+
gen_server2_stats(Config) ->
219+
%% Synthetic test to check the invoke callback, as the bug tested here
220+
%% is only triggered with a race condition.
221+
%% When mirroring is stopped, the backing queue of rabbit_amqqueue_process
222+
%% changes from rabbit_mirror_queue_master to rabbit_priority_queue,
223+
%% which shouldn't receive any invoke call. However, there might
224+
%% be pending messages so the priority queue receives the
225+
%% `run_backing_queue` cast message sent to the old master.
226+
A = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
227+
{Conn, Ch} = rabbit_ct_client_helpers:open_connection_and_channel(Config, A),
228+
Q = <<"gen_server2_stats_queue">>,
229+
declare(Ch, Q, 3),
230+
Pid = queue_pid(Config, A, rabbit_misc:r(<<"/">>, queue, Q)),
231+
Metrics = rabbit_ct_broker_helpers:rpc(
232+
Config, A, rabbit_core_metrics, get_gen_server2_stats,
233+
[Pid]),
234+
true = is_number(Metrics),
235+
delete(Ch, Q),
236+
rabbit_ct_client_helpers:close_channel(Ch),
237+
rabbit_ct_client_helpers:close_connection(Conn),
238+
passed.
239+
216240
dropwhile_fetchwhile(Config) ->
217241
{Conn, Ch} = rabbit_ct_client_helpers:open_connection_and_channel(Config, 0),
218242
Q = <<"dropwhile_fetchwhile-queue">>,

0 commit comments

Comments
 (0)