From c10200138cc8fcd9fbee9ac8792e5edaad598a02 Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Thu, 16 Jul 2015 21:17:46 +0900 Subject: [PATCH] Hooray??! Fix the damn PULSE hangs by using infinity supervisor shutdown times --- src/machi_flu_psup.erl | 11 +++++++---- src/machi_flu_sup.erl | 3 +++ src/machi_sup.erl | 11 +++++++++-- test/machi_chain_manager1_pulse.erl | 23 ++++++++++++++--------- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/machi_flu_psup.erl b/src/machi_flu_psup.erl index d88a4ea..cd8b66d 100644 --- a/src/machi_flu_psup.erl +++ b/src/machi_flu_psup.erl @@ -66,6 +66,9 @@ -ifdef(PULSE). -compile({parse_transform, pulse_instrument}). -include_lib("pulse_otp/include/pulse_otp.hrl"). +-define(SHUTDOWN, infinity). +-else. +-define(SHUTDOWN, 5000). -endif. %% External API @@ -80,7 +83,7 @@ make_package_spec(FluName, TcpPort, DataDir, Props) -> {FluName, {machi_flu_psup, start_link, [FluName, TcpPort, DataDir, Props]}, - permanent, 5000, supervisor, []}. + permanent, ?SHUTDOWN, supervisor, []}. start_flu_package(FluName, TcpPort, DataDir, Props) -> Spec = make_package_spec(FluName, TcpPort, DataDir, Props), @@ -111,15 +114,15 @@ init([FluName, TcpPort, DataDir, Props0]) -> ProjSpec = {ProjRegName, {machi_projection_store, start_link, [ProjRegName, DataDir, FluName]}, - permanent, 5000, worker, []}, + permanent, ?SHUTDOWN, worker, []}, MgrSpec = {make_mgr_supname(FluName), {machi_chain_manager1, start_link, [FluName, [], Props]}, - permanent, 5000, worker, []}, + permanent, ?SHUTDOWN, worker, []}, FluSpec = {FluName, {machi_flu1, start_link, [ [{FluName, TcpPort, DataDir}|Props] ]}, - permanent, 5000, worker, []}, + permanent, ?SHUTDOWN, worker, []}, {ok, {SupFlags, [ProjSpec, MgrSpec, FluSpec]}}. make_p_regname(FluName) when is_atom(FluName) -> diff --git a/src/machi_flu_sup.erl b/src/machi_flu_sup.erl index 8b236d0..23ba5a6 100644 --- a/src/machi_flu_sup.erl +++ b/src/machi_flu_sup.erl @@ -33,6 +33,9 @@ -ifdef(PULSE). -compile({parse_transform, pulse_instrument}). -include_lib("pulse_otp/include/pulse_otp.hrl"). +-define(SHUTDOWN, infinity). +-else. +-define(SHUTDOWN, 5000). -endif. %% API diff --git a/src/machi_sup.erl b/src/machi_sup.erl index 4170413..699cbc9 100644 --- a/src/machi_sup.erl +++ b/src/machi_sup.erl @@ -30,6 +30,9 @@ -ifdef(PULSE). -compile({parse_transform, pulse_instrument}). -include_lib("pulse_otp/include/pulse_otp.hrl"). +-define(SHUTDOWN, infinity). +-else. +-define(SHUTDOWN, 5000). -endif. %% API @@ -44,7 +47,11 @@ start_link() -> supervisor:start_link({local, ?SERVER}, ?MODULE, []). init([]) -> - erlang:display({flu_sup,self()}), + erlang:display({flu_sup,?LINE,self()}), + {_, Ps} = process_info(self(), links), + erlang:display({flu_sup,self(), links, Ps}), + [unlink(P) || P <- Ps], + erlang:display({flu_sup,?LINE,self()}), RestartStrategy = one_for_one, MaxRestarts = 1000, MaxSecondsBetweenRestarts = 3600, @@ -52,7 +59,7 @@ init([]) -> SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts}, Restart = permanent, - Shutdown = 5000, + Shutdown = ?SHUTDOWN, Type = supervisor, ServerSup = diff --git a/test/machi_chain_manager1_pulse.erl b/test/machi_chain_manager1_pulse.erl index f4c637a..ac65342 100644 --- a/test/machi_chain_manager1_pulse.erl +++ b/test/machi_chain_manager1_pulse.erl @@ -307,14 +307,17 @@ dump_state() -> [P || P <- Ps, P#projection_v1.epoch_number /= 0] end} || {Name, Proxy} <- ProxiesDict], - + ?V("~w,", [ [{X,whereis(X)} || X <- [machi_sup, machi_flu_sup, machi_partition_simulator]] ]), + ?V("~w,", [catch application:stop(machi)]), + [?V("~w,", [timer:sleep(10)]) || _ <- lists:seq(1,50)], + ?V("~w,", [ [{X,whereis(X)} || X <- [machi_sup, machi_flu_sup, machi_partition_simulator]] ]), ?V(")", []), Diag1 = Diag2 = "skip_diags", {Report, PrivProjs, lists:flatten([Diag1, Diag2])} catch XX:YY -> ?V("OUCH: ~p ~p @ ~p\n", [XX, YY, erlang:get_stacktrace()]), ?V("Exiting now to move to manual post-mortem....\n", []), - erlang:halt(0), + erlang:halt(66), false end. @@ -489,14 +492,16 @@ erlang:display({hard,?MODULE,?LINE,self()}), (catch unlink(whereis(machi_partition_simulator))), [begin -erlang:display({hard,?MODULE,?LINE,self(),X}), Pid = whereis(X), - %%%%%%DELME deadlock source? spawn(fun() -> ?QC_FMT("shutdown-~w,", [self()]), (catch X:stop()) end), - timer:sleep(50), - timer:sleep(10), - (catch exit(Pid, shutdown)), - timer:sleep(1), - (catch exit(Pid, kill)) +erlang:display({hard,?MODULE,?LINE,self(),X,Pid}), +okokokokokokwhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + %% %%%%%%DELME deadlock source? spawn(fun() -> ?QC_FMT("shutdown-~w,", [self()]), (catch X:stop()) end), + %% timer:sleep(50), + %% timer:sleep(10), + %% (catch exit(Pid, shutdown)), + %% timer:sleep(1), + %% (catch exit(Pid, kill)) + %% end || X <- [machi_partition_simulator] ], end || X <- [machi_partition_simulator, machi_flu_sup, machi_sup] ], timer:sleep(100), ok.