Skip to content

Commit 4e2c7a3

Browse files
authored
Clear the permissions first to prohibit new incoming connections when deleting a vhost.
If a new queue is created while the vhost is being deleted, the new queue will remain. as below: The testvh vhost has been deleted. But there is a queue left in the non-existent testvh [root@Controller1 ~]# rabbitmqctl list_vhosts Listing vhosts ... name / [root@Controller1 ~]# rabbitmqctl list_queues --vhost testvh Timeout: 60.0 seconds ... Listing queues for vhost testvh ... name messages messages_ready messages_unacknowledged consumers ha-1 0 0 0 0
1 parent 4993fef commit 4e2c7a3

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

deps/rabbit/src/rabbit_vhost.erl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ delete(VHost, ActingUser) ->
235235
%% eventually the termination of that process. Exchange deletion causes
236236
%% notifications which must be sent outside the TX
237237
rabbit_log:info("Deleting vhost '~s'", [VHost]),
238+
%% Clear the permissions first to prohibit new incoming connections when deleting a vhost
239+
rabbit_misc:execute_mnesia_transaction(
240+
with(VHost, fun () -> clear_permissions(VHost, ActingUser) end)),
238241
QDelFun = fun (Q) -> rabbit_amqqueue:delete(Q, false, false, ActingUser) end,
239242
[begin
240243
Name = amqqueue:get_name(Q),
@@ -372,13 +375,6 @@ assert_benign({error, {absent, Q, _}}, ActingUser) ->
372375
rabbit_amqqueue:internal_delete(QName, ActingUser).
373376

374377
internal_delete(VHost, ActingUser) ->
375-
[ok = rabbit_auth_backend_internal:clear_permissions(
376-
proplists:get_value(user, Info), VHost, ActingUser)
377-
|| Info <- rabbit_auth_backend_internal:list_vhost_permissions(VHost)],
378-
TopicPermissions = rabbit_auth_backend_internal:list_vhost_topic_permissions(VHost),
379-
[ok = rabbit_auth_backend_internal:clear_topic_permissions(
380-
proplists:get_value(user, TopicPermission), VHost, ActingUser)
381-
|| TopicPermission <- TopicPermissions],
382378
Fs1 = [rabbit_runtime_parameters:clear(VHost,
383379
proplists:get_value(component, Info),
384380
proplists:get_value(name, Info),
@@ -580,3 +576,13 @@ info_all(Ref, AggregatorPid) -> info_all(?INFO_KEYS, Ref, AggregatorPid).
580576
info_all(Items, Ref, AggregatorPid) ->
581577
rabbit_control_misc:emitting_map(
582578
AggregatorPid, Ref, fun(VHost) -> info(VHost, Items) end, all()).
579+
580+
581+
clear_permissions(VHost, ActingUser) ->
582+
[ok = rabbit_auth_backend_internal:clear_permissions(
583+
proplists:get_value(user, Info), VHost, ActingUser)
584+
|| Info <- rabbit_auth_backend_internal:list_vhost_permissions(VHost)],
585+
TopicPermissions = rabbit_auth_backend_internal:list_vhost_topic_permissions(VHost),
586+
[ok = rabbit_auth_backend_internal:clear_topic_permissions(
587+
proplists:get_value(user, TopicPermission), VHost, ActingUser)
588+
|| TopicPermission <- TopicPermissions].

0 commit comments

Comments
 (0)