summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Watson <tim@rabbitmq.com>2013-03-06 20:29:50 +0000
committerTim Watson <tim@rabbitmq.com>2013-03-06 20:29:50 +0000
commitd8b30c8d9baf22bdce5644b2af854f2edb080738 (patch)
treeccc903aa3b1abad8e7f59437027331efc0a9fa86
parent30d4a9ae902c8a8ee9593a4ff603bda06563fbd0 (diff)
downloadrabbitmq-server-d8b30c8d9baf22bdce5644b2af854f2edb080738.tar.gz
Refactor try_again restart handling
-rw-r--r--src/supervisor2.erl46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/supervisor2.erl b/src/supervisor2.erl
index 3f807573..719c8b3c 100644
--- a/src/supervisor2.erl
+++ b/src/supervisor2.erl
@@ -703,8 +703,8 @@ handle_info(Msg, State) ->
delayed_restart(RestartType, Reason, Child, State) ->
case do_restart(RestartType, Reason, Child, State) of
- {ok, NState} -> {noreply, NState};
- {try_again, _, NState} -> {noreply, NState}
+ {ok, NState} -> {noreply, NState};
+ Other -> Other
end.
%%
@@ -879,14 +879,7 @@ do_restart(temporary, Reason, Child, State) ->
do_restart_delay({RestartType, Delay}, Reason, Child, State) ->
case add_restart(State) of
{ok, NState} ->
- restart(NState#state.strategy, Child, NState);
- {try_again, Reason, NState} ->
- %% See restart/2 for an explanation of try_again_restart
- Id = if ?is_simple(State) -> Child#child.pid;
- true -> Child#child.name
- end,
- timer:apply_after(0,?MODULE,try_again_restart,[self(),Id,Reason]),
- {ok, NState};
+ maybe_restart(NState#state.strategy, Child, NState);
{terminate, _NState} ->
%% we've reached the max restart intensity, but the
%% add_restart will have added to the restarts
@@ -910,27 +903,30 @@ del_child_and_maybe_shutdown(_, Child, State) ->
restart(Child, State) ->
case add_restart(State) of
{ok, NState} ->
- case restart(NState#state.strategy, Child, NState) of
- {try_again, Reason, NState2} ->
- %% Leaving control back to gen_server before
- %% trying again. This way other incoming requsts
- %% for the supervisor can be handled - e.g. a
- %% shutdown request for the supervisor or the
- %% child.
- Id = if ?is_simple(State) -> Child#child.pid;
- true -> Child#child.name
- end,
- timer:apply_after(0,?MODULE,try_again_restart,[self(),Id,Reason]),
- {ok,NState2};
- Other ->
- Other
- end;
+ maybe_restart(NState#state.strategy, Child, NState);
{terminate, NState} ->
report_error(shutdown, reached_max_restart_intensity,
Child, State#state.name),
{shutdown, remove_child(Child, NState)}
end.
+maybe_restart(Strategy, Child, State) ->
+ case restart(Strategy, Child, State) of
+ {try_again, Reason, NState2} ->
+ %% Leaving control back to gen_server before
+ %% trying again. This way other incoming requsts
+ %% for the supervisor can be handled - e.g. a
+ %% shutdown request for the supervisor or the
+ %% child.
+ Id = if ?is_simple(State) -> Child#child.pid;
+ true -> Child#child.name
+ end,
+ timer:apply_after(0,?MODULE,try_again_restart,[self(),Id,Reason]),
+ {ok,NState2};
+ Other ->
+ Other
+ end.
+
restart(simple_one_for_one, Child, State) ->
#child{pid = OldPid, mfargs = {M, F, A}} = Child,
Dynamics = ?DICT:erase(OldPid, dynamics_db(Child#child.restart_type,