Merge pull request #2 from cloudant/12713-fail-rexi_DOWN-faster
BugzID: 12713
diff --git a/src/rexi_monitor.erl b/src/rexi_monitor.erl
index 819b6bc..ab33fb8 100644
--- a/src/rexi_monitor.erl
+++ b/src/rexi_monitor.erl
@@ -23,8 +23,12 @@
-spec start([pid() | atom() | {atom(),node()}]) -> pid().
start(Procs) ->
Parent = self(),
+ Nodes = [node() | nodes()],
+ {Mon, Skip} = lists:partition(fun(P) -> should_monitor(P, Nodes) end,
+ Procs),
spawn_link(fun() ->
- [erlang:monitor(process, P) || P <- Procs],
+ [notify_parent(Parent, P, noconnect) || P <- Skip],
+ [erlang:monitor(process, P) || P <- Mon],
wait_monitors(Parent)
end).
@@ -37,10 +41,18 @@
%% internal functions %%
+notify_parent(Parent, Pid, Reason) ->
+ erlang:send(Parent, {rexi_DOWN, self(), Pid, Reason}).
+
+should_monitor(Pid, Nodes) when is_pid(Pid) ->
+ lists:member(node(Pid), Nodes);
+should_monitor({_, Node}, Nodes) ->
+ lists:member(Node, Nodes).
+
wait_monitors(Parent) ->
receive
{'DOWN', _, process, Pid, Reason} ->
- Parent ! {rexi_DOWN, self(), Pid, Reason},
+ notify_parent(Parent, Pid, Reason),
wait_monitors(Parent);
{Parent, shutdown} ->
ok
diff --git a/src/rexi_utils.erl b/src/rexi_utils.erl
index e53df34..b0f2ea2 100644
--- a/src/rexi_utils.erl
+++ b/src/rexi_utils.erl
@@ -46,7 +46,6 @@
Fun(Msg, {Worker, From}, Acc0)
end;
{rexi_DOWN, _RexiMonPid, ServerPid, Reason} = Msg ->
- io:format("rexi_DOWN ~p ~p", [ServerPid, Reason]),
Fun(Msg, nil, Acc0)
after PerMsgTO ->
{timeout, Acc0}