Skip to content

Commit 5967eab

Browse files
committed
Use process status to pass the auto_delete flag
Using a terminate reason makes the channel crash [#159483364]
1 parent ee77a09 commit 5967eab

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/rabbit_amqqueue_process.erl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,16 @@ terminate({shutdown, missing_owner} = Reason, State) ->
287287
terminate({shutdown, _} = R, State = #q{backing_queue = BQ}) ->
288288
rabbit_core_metrics:queue_deleted(qname(State)),
289289
terminate_shutdown(fun (BQS) -> BQ:terminate(R, BQS) end, State);
290-
terminate(normal, State) -> %% delete case
291-
terminate_shutdown(terminate_delete(true, normal, State), State);
292-
terminate(auto_delete, State) -> %% auto_delete case
290+
terminate(normal, State = #q{status = {terminated_by, auto_delete}}) ->
291+
%% auto_delete case
293292
%% To increase performance we want to avoid a mnesia_sync:sync call
294293
%% after every transaction, as we could be deleting simultaneously
295294
%% thousands of queues. A optimisation introduced by server#1513
296295
%% needs to be reverted by this case, avoiding to guard the delete
297296
%% operation on `rabbit_durable_queue`
298297
terminate_shutdown(terminate_delete(true, auto_delete, State), State);
298+
terminate(normal, State) -> %% delete case
299+
terminate_shutdown(terminate_delete(true, normal, State), State);
299300
%% If we crashed don't try to clean up the BQS, probably best to leave it.
300301
terminate(_Reason, State = #q{q = Q}) ->
301302
terminate_shutdown(fun (BQS) ->
@@ -328,11 +329,13 @@ terminate_delete(EmitStats, Reason0,
328329
%% don't care if the internal delete doesn't return 'ok'.
329330
rabbit_amqqueue:internal_delete(QName, ActingUser, Reason0)
330331
catch
331-
{error, Reason} -> error(Reason)
332+
{error, ReasonE} -> error(ReasonE)
332333
end,
333334
BQS1
334335
end.
335336

337+
terminated_by({terminated_by, auto_delete}) ->
338+
?INTERNAL_USER;
336339
terminated_by({terminated_by, ActingUser}) ->
337340
ActingUser;
338341
terminated_by(_) ->
@@ -1178,7 +1181,7 @@ handle_call({notify_down, ChPid}, _From, State) ->
11781181
%% gen_server2 *before* the reply is sent.
11791182
case handle_ch_down(ChPid, State) of
11801183
{ok, State1} -> reply(ok, State1);
1181-
{stop, State1} -> {stop, auto_delete, ok, State1}
1184+
{stop, State1} -> stop(ok, State1#q{status = {terminated_by, auto_delete}})
11821185
end;
11831186

11841187
handle_call({basic_get, ChPid, NoAck, LimiterPid}, _From,

0 commit comments

Comments
 (0)