summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Watson <tim@rabbitmq.com>2013-06-05 15:53:35 +0100
committerTim Watson <tim@rabbitmq.com>2013-06-05 15:53:35 +0100
commita41af647791ac3a3de76364c7e352863c106f50e (patch)
treebcb351950f6bb9a7720eb78ff7d158615f305462
parentef21df62c9d6cf25d95ea5410c1de66912e27d9c (diff)
parent44a1b659c4253939e889bb85c96af86106c9f35d (diff)
downloadrabbitmq-server-a41af647791ac3a3de76364c7e352863c106f50e.tar.gz
merge bug25567 into stable
-rw-r--r--src/app_utils.erl2
-rw-r--r--src/rabbit.erl4
-rw-r--r--src/rabbit_guid.erl5
-rw-r--r--src/rabbit_misc.erl13
-rw-r--r--src/rabbit_node_monitor.erl2
-rw-r--r--src/rabbit_nodes.erl2
-rw-r--r--src/rabbit_plugins.erl2
-rw-r--r--src/rabbit_vm.erl2
8 files changed, 24 insertions, 8 deletions
diff --git a/src/app_utils.erl b/src/app_utils.erl
index 8da436c0..b102ce75 100644
--- a/src/app_utils.erl
+++ b/src/app_utils.erl
@@ -93,7 +93,7 @@ app_dependency_order(RootApps, StripUnreachable) ->
%% Private API
wait_for_application(Application) ->
- case lists:keymember(Application, 1, application:which_applications()) of
+ case lists:keymember(Application, 1, rabbit_misc:which_applications()) of
true -> ok;
false -> timer:sleep(1000),
wait_for_application(Application)
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 3cfa21ba..450a7f32 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -393,7 +393,7 @@ await_startup() ->
status() ->
S1 = [{pid, list_to_integer(os:getpid())},
- {running_applications, application:which_applications(infinity)},
+ {running_applications, rabbit_misc:which_applications()},
{os, os:type()},
{erlang_version, erlang:system_info(system_version)},
{memory, rabbit_vm:memory()}],
@@ -421,7 +421,7 @@ status() ->
is_running() -> is_running(node()).
-is_running(Node) -> rabbit_nodes:is_running(Node, rabbit).
+is_running(Node) -> rabbit_nodes:is_process_running(Node, rabbit).
environment() ->
lists:keysort(1, [P || P = {K, _} <- application:get_all_env(rabbit),
diff --git a/src/rabbit_guid.erl b/src/rabbit_guid.erl
index 6c45deea..bec29e59 100644
--- a/src/rabbit_guid.erl
+++ b/src/rabbit_guid.erl
@@ -63,6 +63,7 @@ update_disk_serial() ->
Filename = filename(),
Serial = case rabbit_file:read_term_file(Filename) of
{ok, [Num]} -> Num;
+ {ok, []} -> 0; %% [1]
{error, enoent} -> 0;
{error, Reason} ->
throw({error, {cannot_read_serial_file, Filename, Reason}})
@@ -73,6 +74,10 @@ update_disk_serial() ->
throw({error, {cannot_write_serial_file, Filename, Reason1}})
end,
Serial.
+%% [1] a couple of users have reported startup failures due to the
+%% file being empty, presumably as a result of filesystem
+%% corruption. While rabbit doesn't cope with that in general, in this
+%% specific case we can be more accommodating.
%% Generate an un-hashed guid.
fresh() ->
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index c36fb147..a1e95fd5 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -61,7 +61,7 @@
-export([multi_call/2]).
-export([os_cmd/1]).
-export([gb_sets_difference/2]).
--export([version/0]).
+-export([version/0, which_applications/0]).
-export([sequence_error/1]).
-export([json_encode/1, json_decode/1, json_to_term/1, term_to_json/1]).
-export([check_expiry/1]).
@@ -232,6 +232,7 @@
-spec(os_cmd/1 :: (string()) -> string()).
-spec(gb_sets_difference/2 :: (gb_set(), gb_set()) -> gb_set()).
-spec(version/0 :: () -> string()).
+-spec(which_applications/0 :: () -> [{atom(), string(), string()}]).
-spec(sequence_error/1 :: ([({'error', any()} | any())])
-> {'error', any()} | any()).
-spec(json_encode/1 :: (any()) -> {'ok', string()} | {'error', any()}).
@@ -985,6 +986,16 @@ version() ->
{ok, VSN} = application:get_key(rabbit, vsn),
VSN.
+%% application:which_applications(infinity) is dangerous, since it can
+%% cause deadlocks on shutdown. So we have to use a timeout variant,
+%% but w/o creating spurious timeout errors.
+which_applications() ->
+ try
+ application:which_applications()
+ catch
+ exit:{timeout, _} -> []
+ end.
+
sequence_error([T]) -> T;
sequence_error([{error, _} = Error | _]) -> Error;
sequence_error([_ | Rest]) -> sequence_error(Rest).
diff --git a/src/rabbit_node_monitor.erl b/src/rabbit_node_monitor.erl
index 7d844c72..7fcd1f99 100644
--- a/src/rabbit_node_monitor.erl
+++ b/src/rabbit_node_monitor.erl
@@ -465,4 +465,4 @@ alive_nodes(Nodes) -> [N || N <- Nodes, pong =:= net_adm:ping(N)].
alive_rabbit_nodes() -> alive_rabbit_nodes(rabbit_mnesia:cluster_nodes(all)).
alive_rabbit_nodes(Nodes) ->
- [N || N <- alive_nodes(Nodes), rabbit_nodes:is_process_running(N, rabbit)].
+ [N || N <- alive_nodes(Nodes), rabbit:is_running(N)].
diff --git a/src/rabbit_nodes.erl b/src/rabbit_nodes.erl
index 5640f12a..b85646d2 100644
--- a/src/rabbit_nodes.erl
+++ b/src/rabbit_nodes.erl
@@ -96,7 +96,7 @@ cookie_hash() ->
base64:encode_to_string(erlang:md5(atom_to_list(erlang:get_cookie()))).
is_running(Node, Application) ->
- case rpc:call(Node, application, which_applications, [infinity]) of
+ case rpc:call(Node, rabbit_misc, which_applications, []) of
{badrpc, _} -> false;
Apps -> proplists:is_defined(Application, Apps)
end.
diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl
index 58c906eb..6f6515b0 100644
--- a/src/rabbit_plugins.erl
+++ b/src/rabbit_plugins.erl
@@ -47,7 +47,7 @@ setup() ->
active() ->
{ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir),
InstalledPlugins = [ P#plugin.name || P <- list(ExpandDir) ],
- [App || {App, _, _} <- application:which_applications(),
+ [App || {App, _, _} <- rabbit_misc:which_applications(),
lists:member(App, InstalledPlugins)].
%% @doc Get the list of plugins which are ready to be enabled.
diff --git a/src/rabbit_vm.erl b/src/rabbit_vm.erl
index c28b0cd5..e97824b9 100644
--- a/src/rabbit_vm.erl
+++ b/src/rabbit_vm.erl
@@ -99,7 +99,7 @@ bytes(Words) -> Words * erlang:system_info(wordsize).
plugin_sups() ->
lists:append([plugin_sup(App) ||
- {App, _, _} <- application:which_applications(),
+ {App, _, _} <- rabbit_misc:which_applications(),
is_plugin(atom_to_list(App))]).
plugin_sup(App) ->