diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2014-07-21 10:50:18 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2014-07-21 10:50:18 +0100 |
commit | 1843130ffcc97618634a014829c17bfc638c2e29 (patch) | |
tree | 5ffdb67c50d62308135ccf2785b0c8c229225064 | |
parent | 8a22eda4066cb49309e26e16d12609fbe839ca57 (diff) | |
download | rabbitmq-server-bug26295.tar.gz |
Fix await_startup/1. Change its design from "figure out what apps we should be running and wait for them" to "wait for the boot marker to go away".bug26295
-rw-r--r-- | src/app_utils.erl | 14 | ||||
-rw-r--r-- | src/rabbit.erl | 34 |
2 files changed, 21 insertions, 27 deletions
diff --git a/src/app_utils.erl b/src/app_utils.erl index e321888d..87e6fa0b 100644 --- a/src/app_utils.erl +++ b/src/app_utils.erl @@ -17,7 +17,7 @@ -export([load_applications/1, start_applications/1, start_applications/2, stop_applications/1, stop_applications/2, app_dependency_order/2, - wait_for_applications/1, app_dependencies/1]). + app_dependencies/1]). -ifdef(use_specs). @@ -28,7 +28,6 @@ -spec stop_applications([atom()]) -> 'ok'. -spec start_applications([atom()], error_handler()) -> 'ok'. -spec stop_applications([atom()], error_handler()) -> 'ok'. --spec wait_for_applications([atom()]) -> 'ok'. -spec app_dependency_order([atom()], boolean()) -> [digraph:vertex()]. -spec app_dependencies(atom()) -> [atom()]. @@ -69,10 +68,6 @@ stop_applications(Apps, ErrorHandler) -> ErrorHandler, Apps). - -wait_for_applications(Apps) -> - [wait_for_application(App) || App <- Apps], ok. - app_dependency_order(RootApps, StripUnreachable) -> {ok, G} = rabbit_misc:build_acyclic_graph( fun ({App, _Deps}) -> [{App, App}] end, @@ -93,13 +88,6 @@ app_dependency_order(RootApps, StripUnreachable) -> %%--------------------------------------------------------------------------- %% Private API -wait_for_application(Application) -> - case lists:keymember(Application, 1, rabbit_misc:which_applications()) of - true -> ok; - false -> timer:sleep(1000), - wait_for_application(Application) - end. - load_applications(Worklist, Loaded) -> case queue:out(Worklist) of {empty, _WorkList} -> diff --git a/src/rabbit.erl b/src/rabbit.erl index a4c460ae..191f04a4 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -365,10 +365,11 @@ start_it(StartFun) -> stop() -> case whereis(rabbit_boot) of undefined -> ok; - _ -> await_startup() + _ -> await_startup(true) end, rabbit_log:info("Stopping RabbitMQ~n"), - stop_apps(app_shutdown_order()). + Apps = ?APPS ++ rabbit_plugins:active(), + stop_apps(app_utils:app_dependency_order(Apps, true)). stop_and_halt() -> try @@ -410,7 +411,20 @@ run_cleanup_steps(Apps) -> ok. await_startup() -> - app_utils:wait_for_applications(app_startup_order()). + await_startup(false). + +await_startup(HaveSeenRabbitBoot) -> + %% We don't take absence of rabbit_boot as evidence we've started, + %% since there's a small window before it is registered. + case whereis(rabbit_boot) of + undefined -> case HaveSeenRabbitBoot orelse is_running() of + true -> ok; + false -> timer:sleep(100), + await_startup(false) + end; + _ -> timer:sleep(100), + await_startup(true) + end. status() -> S1 = [{pid, list_to_integer(os:getpid())}, @@ -461,6 +475,9 @@ listeners() -> ip_address = IP, port = Port} <- Listeners, Node =:= node()]. +%% TODO this only determines if the rabbit application has started, +%% not if it is running, never mind plugins. It would be nice to have +%% more nuance here. is_running() -> is_running(node()). is_running(Node) -> rabbit_nodes:is_process_running(Node, rabbit). @@ -508,17 +525,6 @@ stop(_State) -> ok. %%--------------------------------------------------------------------------- -%% application life cycle - -app_startup_order() -> - ok = app_utils:load_applications(?APPS), - app_utils:app_dependency_order(?APPS, false). - -app_shutdown_order() -> - Apps = ?APPS ++ rabbit_plugins:active(), - app_utils:app_dependency_order(Apps, true). - -%%--------------------------------------------------------------------------- %% boot step logic run_boot_steps() -> |