Skip to content

Commit 0ed0fb8

Browse files
the-mikedavismergify[bot]
authored andcommitted
rabbit_vhost:delete/2: Return no_such_vhost when the vhost isn't deleted
Previously `rabbit_vhost:delete/2` threw this error within `rabbit_policy:list/2` when the vhost didn't exist. We can return the value instead so that `rabbitmqctl delete_vhost` behaves the same between these changes and the branch fork point. The `rabbit_vhost_sup_sup:delete_on_all_nodes/1` cleanup is idempotent so we can run all teardown steps for the vhost and return this error instead. This might be useful if deletion fails for some resources under the vhost, for example a queue. If the vhost record is gone it might still be useful to try to clean up the vhost's resources. (cherry picked from commit 39c6093)
1 parent 3a6d9f5 commit 0ed0fb8

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

deps/rabbit/src/rabbit_vhost.erl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,19 @@ delete(VHost, ActingUser) ->
285285
rabbit_log:info("Clearing policies and runtime parameters in vhost '~ts' because it's being deleted", [VHost]),
286286
_ = rabbit_runtime_parameters:clear_vhost(VHost, ActingUser),
287287
rabbit_log:debug("Removing vhost '~ts' from the metadata storage because it's being deleted", [VHost]),
288-
case rabbit_db_vhost:delete(VHost) of
289-
true ->
290-
ok = rabbit_event:notify(
291-
vhost_deleted,
292-
[{name, VHost},
293-
{user_who_performed_action, ActingUser}]);
294-
false ->
295-
ok
296-
end,
288+
Ret = case rabbit_db_vhost:delete(VHost) of
289+
true ->
290+
ok = rabbit_event:notify(
291+
vhost_deleted,
292+
[{name, VHost},
293+
{user_who_performed_action, ActingUser}]);
294+
false ->
295+
{error, {no_such_vhost, VHost}}
296+
end,
297297
%% After vhost was deleted from the database, we try to stop vhost
298298
%% supervisors on all the nodes.
299299
rabbit_vhost_sup_sup:delete_on_all_nodes(VHost),
300-
ok.
300+
Ret.
301301

302302
-spec put_vhost(vhost:name(),
303303
binary(),

deps/rabbitmq_management/src/rabbit_mgmt_wm_vhost.erl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ accept_content(ReqData0, Context = #context{user = #user{username = Username}})
8888

8989
delete_resource(ReqData, Context = #context{user = #user{username = Username}}) ->
9090
VHost = id(ReqData),
91-
try
92-
rabbit_vhost:delete(VHost, Username)
93-
catch _:{error, {no_such_vhost, _}} ->
94-
ok
95-
end,
91+
_ = rabbit_vhost:delete(VHost, Username),
9692
{true, ReqData, Context}.
9793

9894
is_authorized(ReqData, Context) ->

0 commit comments

Comments
 (0)