diff options
| author | Emile Joubert <emile@rabbitmq.com> | 2011-11-01 16:39:45 +0000 |
|---|---|---|
| committer | Emile Joubert <emile@rabbitmq.com> | 2011-11-01 16:39:45 +0000 |
| commit | 2a979749ccd6c0cc1f6612ae19aded3685113b63 (patch) | |
| tree | 1064c6e79c43375fba6e86fc7dfa0d3973f8851b | |
| parent | 6f8aefa84ee409f1ac9590d79cf810fefa7d7479 (diff) | |
| download | rabbitmq-server-git-2a979749ccd6c0cc1f6612ae19aded3685113b63.tar.gz | |
More accurate timeouts during supervisor shutdown
| -rw-r--r-- | src/supervisor2.erl | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/supervisor2.erl b/src/supervisor2.erl index 0f8e9d735c..27115e2279 100644 --- a/src/supervisor2.erl +++ b/src/supervisor2.erl @@ -660,10 +660,17 @@ terminate_simple_children(Child, Dynamics, SupName) -> exit(Pid, ExitReason), [Pid | Pids] end, [], Dynamics), + Ref = make_ref(), + {ok, TRef} = timer:send_after(Timeout, {timeout, Ref}), {Replies, _Timedout} = lists:foldl( fun (_Pid, {Replies, Timedout}) -> receive + {timeout, Ref} -> + [exit(P, kill) || P <- Pids -- dict:fetch_keys(Replies)], + receive {'DOWN', _, process, Pid, Reason} -> + {dict:append(Pid, {error, Reason}, Replies), true} + end; {'DOWN', _MRef, process, Pid, Reason} when Child#child.shutdown == brutal_kill andalso Reason == killed andalso Timedout == false orelse @@ -675,19 +682,9 @@ terminate_simple_children(Child, Dynamics, SupName) -> receive {'DOWN', _MRef, process, Pid, _} -> {dict:append(Pid, {error, Reason}, Replies), Timedout} end - after Timeout -> - case Timedout of - false -> lists:foldl(fun (Pid, ok) -> exit(Pid, kill) end, - Pids -- dict:fetch_keys(Replies)); - true -> ok %% actually not ok - we await replies to kill - %% signals after 2 timeouts - end, - receive {'DOWN', _, process, Pid, Reason} -> - {dict:append(Pid, {error, Reason}, Replies), - true} - end end end, {dict:new(), false}, Pids), + timer:cancel(TRef), RestartPerm = case Child#child.restart_type of permanent -> true; {permanent, _Delay} -> true; |
