Skip to content

Commit edbf454

Browse files
Merge pull request #9925 from Ayanda-D/robust-mgmt-api-queue-deletion
Handle different queue states on queue deletion from the management API more robustly
2 parents 575045f + 324debe commit edbf454

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

deps/rabbit/src/amqqueue.erl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
is_amqqueue/1,
7474
is_auto_delete/1,
7575
is_durable/1,
76+
is_exclusive/1,
7677
is_classic/1,
7778
is_quorum/1,
7879
pattern_match_all/0,
@@ -557,6 +558,11 @@ is_auto_delete(#amqqueue{auto_delete = AutoDelete}) ->
557558

558559
is_durable(#amqqueue{durable = Durable}) -> Durable.
559560

561+
-spec is_exclusive(amqqueue()) -> boolean().
562+
563+
is_exclusive(Queue) ->
564+
is_pid(get_exclusive_owner(Queue)).
565+
560566
-spec is_classic(amqqueue()) -> boolean().
561567

562568
is_classic(Queue) ->

deps/rabbitmq_management/src/rabbit_mgmt_wm_queue.erl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,13 @@ delete_resource(ReqData, Context = #context{user = #user{username = ActingUser}}
8181
Name = rabbit_misc:r(VHost, queue, QName),
8282
case rabbit_amqqueue:lookup(Name) of
8383
{ok, Q} ->
84-
case rabbit_amqqueue:delete(Q, IfUnused, IfEmpty, ActingUser) of
84+
IsExclusive = amqqueue:is_exclusive(Q),
85+
ExclusiveOwnerPid = amqqueue:get_exclusive_owner(Q),
86+
try rabbit_amqqueue:delete_with(Q, ExclusiveOwnerPid, IfUnused, IfEmpty, ActingUser, IsExclusive) of
8587
{ok, _} ->
86-
{true, ReqData, Context};
87-
{error, not_empty} ->
88-
Explanation = io_lib:format("~ts not empty", [rabbit_misc:rs(Name)]),
89-
rabbit_log:warning("Delete queue error: ~ts", [Explanation]),
90-
rabbit_mgmt_util:bad_request(list_to_binary(Explanation), ReqData, Context);
91-
{error, in_use} ->
92-
Explanation = io_lib:format("~ts in use", [rabbit_misc:rs(Name)]),
88+
{true, ReqData, Context}
89+
catch
90+
_:#amqp_error{explanation = Explanation} ->
9391
rabbit_log:warning("Delete queue error: ~ts", [Explanation]),
9492
rabbit_mgmt_util:bad_request(list_to_binary(Explanation), ReqData, Context)
9593
end;

deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ all_tests() -> [
8383
multiple_invalid_connections_test,
8484
exchanges_test,
8585
queues_test,
86+
crashed_queues_test,
8687
quorum_queues_test,
8788
stream_queues_have_consumers_field,
8889
bindings_test,
@@ -1078,6 +1079,36 @@ queues_test(Config) ->
10781079
http_delete(Config, "/queues/downvhost/bar", {group, '2xx'}),
10791080
passed.
10801081

1082+
crashed_queues_test(Config) ->
1083+
Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
1084+
Q = #resource{virtual_host = <<"/">>, kind = queue, name = <<"crashingqueue">>},
1085+
1086+
QArgs = #{},
1087+
http_put(Config, "/queues/%2F/crashingqueue", QArgs, {group, '2xx'}),
1088+
1089+
ok = rabbit_ct_broker_helpers:rpc(Config, 0,
1090+
rabbit_amqqueue_control, await_state, [Node, Q, running]),
1091+
1092+
ok = rabbit_ct_broker_helpers:rpc(Config, 0,
1093+
rabbit_amqqueue, kill_queue_hard, [Node, Q]),
1094+
1095+
ok = rabbit_ct_broker_helpers:rpc(Config, 0,
1096+
rabbit_amqqueue_control, await_state, [Node, Q, crashed]),
1097+
1098+
CrashedQueue = http_get(Config, "/queues/%2F/crashingqueue"),
1099+
1100+
assert_item(#{name => <<"crashingqueue">>,
1101+
vhost => <<"/">>,
1102+
state => <<"crashed">>,
1103+
durable => false,
1104+
auto_delete => false,
1105+
exclusive => false,
1106+
arguments => #{}}, CrashedQueue),
1107+
1108+
http_delete(Config, "/queues/%2F/crashingqueue", {group, '2xx'}),
1109+
http_delete(Config, "/queues/%2F/crashingqueue", ?NOT_FOUND),
1110+
passed.
1111+
10811112
quorum_queues_test(Config) ->
10821113
%% Test in a loop that no metrics are left behing after deleting a queue
10831114
quorum_queues_test_loop(Config, 5).

0 commit comments

Comments
 (0)