CQ: 'handle_cast(init, State) ' may cause exceptions

In the init_it2 function, when returning stop with none 'From'. This will result in the following exceptions:

2025-06-28 16:01:15.636 [error] <0.1306.0>   crasher:, initial call: rabbit_amqqueue_process:init/1, pid: <0.1306.0>, registered_name: [], exception exit: {bad_return_value, {stop,normal, {existing, {amqqueue, {resource,<<"/">>,queue,<<"q13">>}, false,false,none, [{<<"x-queue-type">>,longstr, <<"classic">>}], <14981.1295.0>,[],[],[],undefined, undefined,[],[],live,0,[],<<"/">>, #{user => <<"rabbit_inside_user">>, system_creation => 1751098305370332559, recover_on_declare => true, creator =>, {1751099091,"10.225.80.5",50046, "none"}, last_system_creation =>, 1751096873022515385}, rabbit_classic_queue,#{}}}, {q,{amqqueue, {resource,<<"/">>,queue,<<"q13">>}, false,false,none, [{<<"x-queue-type">>,longstr, <<"classic">>}], <0.1306.0>,[],[],[],undefined,undefined,[], [],crashed,0,[],<<"/">>, #{user => <<"rabbit_inside_user">>, system_creation => 1751096873022515385, recover_on_declare => false, creator =>, {1751097374,"10.225.80.5",56254, "none"}, recover_vsn => 0, zretarts => [-576459962]}, rabbit_classic_queue,#{}}, none,false,undefined,undefined, {state, {queue,[],[],0}, {active,-576459961468389,1.0}, []}, undefined,undefined,undefined,undefined, {state,none,30000,undefined}, #{},undefined,undefined,undefined, {state,#{},delegate}, undefined,undefined,undefined,undefined, 'drop-head',0,0,running,false,0,undefined, <<"/">>,undefined,0,false,0,undefined,0,0,0,[], undefined,0,0,0,0,true}}}, in function  gen_server2:terminate/3 (gen_server2.erl, line 1172), ancestors: [<0.1089.0>,<0.511.0>,<0.471.0>,<0.470.0>, rabbit_vhost_sup_sup,rabbit_sup,<0.250.0>], message_queue_len: 0, messages: [], links: [<0.1089.0>], dictionary: [{virtual_host,<<"/">>}, {rand_seed, {#{max => 288230376151711743,type => exsplus, next => #Fun<rand.5.65977474>, jump => #Fun<rand.3.65977474>}, [134188285183854767|82006587006243019]}}, {debug_openv_dt_cfg,{1751097655,[1]}}, {process_name, {rabbit_amqqueue_process, {resource,<<"/">>,queue,<<"q13">>}}}], trap_exit: true, status: running, heap_size: 28690, stack_size: 28, reductions: 46062, neighbours:,

(cherry picked from commit e6ec4df9bb)
(cherry picked from commit 1afbdca365)
This commit is contained in:
tomyouyou 2025-06-28 16:41:23 +08:00 committed by Mergify
parent be3aa5bee1
commit c23ded53bd
1 changed files with 8 additions and 3 deletions

View File

@ -202,6 +202,11 @@ init_it(Recover, From, State = #q{q = Q0}) ->
State#q{backing_queue = BQ, backing_queue_state = BQS}}}
end.
stop_for_init(none, {Operation, Reason, _Reply, State}) ->
{Operation, Reason, State};
stop_for_init(_From, Result) ->
Result.
init_it2(Recover, From, State = #q{q = Q,
backing_queue = undefined,
backing_queue_state = undefined}) ->
@ -226,16 +231,16 @@ init_it2(Recover, From, State = #q{q = Q,
fun() -> emit_stats(State1) end),
noreply(State1);
false ->
{stop, normal, {existing, Q1}, State}
stop_for_init(From, {stop, normal, {existing, Q1}, State})
end;
{error, timeout} ->
Reason = {protocol_error, internal_error,
"Could not declare ~ts on node '~ts' because the "
"metadata store operation timed out",
[rabbit_misc:rs(amqqueue:get_name(Q)), node()]},
{stop, normal, Reason, State};
stop_for_init(From, {stop, normal, Reason, State});
Err ->
{stop, normal, Err, State}
stop_for_init(From, {stop, normal, Err, State})
end.
recovery_status(new) -> {no_barrier, new};