@@ -708,9 +708,9 @@ hibernate(GS2State = #gs2_state { timeout_state = TimeoutState }) ->
708
708
proc_lib :hibernate (? MODULE , wake_hib ,
709
709
[GS2State # gs2_state { timeout_state = TS }]).
710
710
711
- pre_hibernate (GS2State = # gs2_state { state = State ,
712
- mod = Mod }) ->
713
- rabbit_event : stop_stats_timer ( GS2State , # gs2_state . timer ),
711
+ pre_hibernate (GS2State0 = # gs2_state { state = State ,
712
+ mod = Mod }) ->
713
+ GS2State = maybe_stop_stats ( GS2State0 ),
714
714
case erlang :function_exported (Mod , handle_pre_hibernate , 1 ) of
715
715
true ->
716
716
case catch Mod :handle_pre_hibernate (State ) of
@@ -723,18 +723,19 @@ pre_hibernate(GS2State = #gs2_state { state = State,
723
723
hibernate (GS2State )
724
724
end .
725
725
726
- post_hibernate (GS2State = # gs2_state { state = State ,
727
- mod = Mod ,
728
- init_stats_fun = InitStatsFun }) ->
726
+ post_hibernate (GS2State0 = # gs2_state { state = State ,
727
+ mod = Mod ,
728
+ init_stats_fun = InitStatsFun }) ->
729
+ GS2State = InitStatsFun (GS2State0 ),
729
730
case erlang :function_exported (Mod , handle_post_hibernate , 1 ) of
730
731
true ->
731
732
case catch Mod :handle_post_hibernate (State ) of
732
733
{noreply , NState } ->
733
- process_next_msg (InitStatsFun ( GS2State # gs2_state { state = NState ,
734
- time = infinity }) );
734
+ process_next_msg (GS2State # gs2_state { state = NState ,
735
+ time = infinity });
735
736
{noreply , NState , Time } ->
736
- process_next_msg (InitStatsFun ( GS2State # gs2_state { state = NState ,
737
- time = Time }) );
737
+ process_next_msg (GS2State # gs2_state { state = NState ,
738
+ time = Time });
738
739
Reply ->
739
740
handle_common_termination (Reply , post_hibernate , GS2State )
740
741
end ;
@@ -745,7 +746,7 @@ post_hibernate(GS2State = #gs2_state { state = State,
745
746
% % still set to hibernate, iff that msg is the very msg
746
747
% % that woke us up (or the first msg we receive after
747
748
% % waking up).
748
- process_next_msg (InitStatsFun ( GS2State # gs2_state { time = hibernate }) )
749
+ process_next_msg (GS2State # gs2_state { time = hibernate })
749
750
end .
750
751
751
752
adjust_timeout_state (SleptAt , AwokeAt , {backoff , CurrentTO , MinimumTO ,
@@ -1383,5 +1384,10 @@ emit_stats(GS2State = #gs2_state{queue = Queue}) ->
1383
1384
# gs2_state .timer , emit_gen_server2_stats ).
1384
1385
1385
1386
stop_stats (GS2State ) ->
1386
- _ = rabbit_event : stop_stats_timer (GS2State , # gs2_state . timer ),
1387
+ maybe_stop_stats (GS2State ),
1387
1388
rabbit_core_metrics :gen_server2_deleted (self ()).
1389
+
1390
+ maybe_stop_stats (# gs2_state {timer = undefined } = GS2State ) ->
1391
+ GS2State ;
1392
+ maybe_stop_stats (GS2State ) ->
1393
+ rabbit_event :stop_stats_timer (GS2State , # gs2_state .timer ).
0 commit comments