Skip to content
This repository was archived by the owner on Nov 17, 2020. It is now read-only.

Commit 0543b47

Browse files
committed
Stop stats only if they have been initialised
* Detected on unit tests, it should never happen on a rabbit node
1 parent 157d044 commit 0543b47

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/gen_server2.erl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -708,9 +708,9 @@ hibernate(GS2State = #gs2_state { timeout_state = TimeoutState }) ->
708708
proc_lib:hibernate(?MODULE, wake_hib,
709709
[GS2State #gs2_state { timeout_state = TS }]).
710710

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),
714714
case erlang:function_exported(Mod, handle_pre_hibernate, 1) of
715715
true ->
716716
case catch Mod:handle_pre_hibernate(State) of
@@ -723,18 +723,19 @@ pre_hibernate(GS2State = #gs2_state { state = State,
723723
hibernate(GS2State)
724724
end.
725725

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),
729730
case erlang:function_exported(Mod, handle_post_hibernate, 1) of
730731
true ->
731732
case catch Mod:handle_post_hibernate(State) of
732733
{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 });
735736
{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 });
738739
Reply ->
739740
handle_common_termination(Reply, post_hibernate, GS2State)
740741
end;
@@ -745,7 +746,7 @@ post_hibernate(GS2State = #gs2_state { state = State,
745746
%% still set to hibernate, iff that msg is the very msg
746747
%% that woke us up (or the first msg we receive after
747748
%% waking up).
748-
process_next_msg(InitStatsFun(GS2State #gs2_state { time = hibernate }))
749+
process_next_msg(GS2State #gs2_state { time = hibernate })
749750
end.
750751

751752
adjust_timeout_state(SleptAt, AwokeAt, {backoff, CurrentTO, MinimumTO,
@@ -1383,5 +1384,10 @@ emit_stats(GS2State = #gs2_state{queue = Queue}) ->
13831384
#gs2_state.timer, emit_gen_server2_stats).
13841385

13851386
stop_stats(GS2State) ->
1386-
_ = rabbit_event:stop_stats_timer(GS2State, #gs2_state.timer),
1387+
maybe_stop_stats(GS2State),
13871388
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

Comments
 (0)