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 | 38e1147ba7dc3bf9091d19103ed6fc056dca59c0 (patch) | |
tree | 1064c6e79c43375fba6e86fc7dfa0d3973f8851b | |
parent | de4de5ff0b2cd2fab40ebf6e7a292f05801c8dbb (diff) | |
download | rabbitmq-server-38e1147ba7dc3bf9091d19103ed6fc056dca59c0.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 0f8e9d73..27115e22 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; |