Skip to content

Commit cba540b

Browse files
Fix rabbit_priority_queue:update_rates bug (#11814) (#11819)
updates_rates fails after publishing a message to a queue with priorities enabled. (cherry picked from commit ae41f65) Co-authored-by: Michal Kuratczyk <[email protected]>
1 parent ff9301c commit cba540b

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

deps/rabbit/src/rabbit_priority_queue.erl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ depth(#passthrough{bq = BQ, bqs = BQS}) ->
329329
BQ:depth(BQS).
330330

331331
update_rates(State = #state{bq = BQ}) ->
332-
fold_min2(fun (_P, BQSN) -> BQ:update_rates(BQSN) end, State);
332+
foreach1(fun (_P, BQSN) -> BQ:update_rates(BQSN) end, State);
333333
update_rates(State = #passthrough{bq = BQ, bqs = BQS}) ->
334334
?passthrough1(update_rates(BQS)).
335335

@@ -490,13 +490,6 @@ fold_add2(Fun, State) ->
490490
{add_maybe_infinity(Res, Acc), BQSN1}
491491
end, 0, State).
492492

493-
%% Fold over results assuming results are numbers and we want the minimum
494-
fold_min2(Fun, State) ->
495-
fold2(fun (P, BQSN, Acc) ->
496-
{Res, BQSN1} = Fun(P, BQSN),
497-
{erlang:min(Res, Acc), BQSN1}
498-
end, infinity, State).
499-
500493
%% Fold over results assuming results are lists and we want to append
501494
%% them, and also that we have some AckTags we want to pass in to each
502495
%% invocation.

deps/rabbit/test/priority_queue_SUITE.erl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ groups() ->
4040
invoke,
4141
gen_server2_stats,
4242
negative_max_priorities,
43-
max_priorities_above_hard_limit
43+
max_priorities_above_hard_limit,
44+
update_rates
4445
]}
4546
].
4647

@@ -473,6 +474,24 @@ unknown_info_key(Config) ->
473474
rabbit_ct_client_helpers:close_connection(Conn),
474475
passed.
475476

477+
update_rates(Config) ->
478+
Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
479+
{Conn, Ch} = rabbit_ct_client_helpers:open_connection_and_channel(Config, 0),
480+
Q = <<"update_rates-queue">>,
481+
declare(Ch, Q, [{<<"x-max-priority">>, byte, 3}]),
482+
QPid = queue_pid(Config, Node, rabbit_misc:r(<<"/">>, queue, Q)),
483+
try
484+
publish1(Ch, Q, 1),
485+
QPid ! update_rates,
486+
State = get_state(Config, Q),
487+
?assertEqual(live, State),
488+
delete(Ch, Q)
489+
after
490+
rabbit_ct_client_helpers:close_channel(Ch),
491+
rabbit_ct_client_helpers:close_connection(Conn),
492+
passed
493+
end.
494+
476495
%%----------------------------------------------------------------------------
477496

478497
declare(Ch, Q, Args) when is_list(Args) ->
@@ -590,4 +609,14 @@ info(Config, Q, InfoKeys) ->
590609
Config, Nodename,
591610
rabbit_classic_queue, info, [Amq, InfoKeys]),
592611
{ok, Info}.
612+
613+
get_state(Config, Q) ->
614+
Nodename = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
615+
{ok, Amq} = rabbit_ct_broker_helpers:rpc(
616+
Config, Nodename,
617+
rabbit_amqqueue, lookup, [rabbit_misc:r(<<"/">>, queue, Q)]),
618+
rabbit_ct_broker_helpers:rpc(
619+
Config, Nodename,
620+
amqqueue, get_state, [Amq]).
621+
593622
%%----------------------------------------------------------------------------

0 commit comments

Comments
 (0)