Monitor the db update listener process We were waiting on a receive with an infinite timeout. If the update process happened to exit before we tried asking for the current state we would end up waiting forever for a response.
This just mimics the general gen:do_call/4 pattern of using a monitor to make sure we know if the process has died. Project: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/commit/797954d5 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/tree/797954d5 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/diff/797954d5 Branch: refs/heads/import Commit: 797954d5fa472813c29d9b09bd0915ffea840528 Parents: 95dae3c Author: Paul J. Davis <[email protected]> Authored: Mon Nov 26 12:13:41 2012 -0600 Committer: Paul J. Davis <[email protected]> Committed: Mon Nov 26 14:20:05 2012 -0600 ---------------------------------------------------------------------- src/fabric_db_update_listener.erl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/797954d5/src/fabric_db_update_listener.erl ---------------------------------------------------------------------- diff --git a/src/fabric_db_update_listener.erl b/src/fabric_db_update_listener.erl index 88d3bab..572e955 100644 --- a/src/fabric_db_update_listener.erl +++ b/src/fabric_db_update_listener.erl @@ -103,9 +103,14 @@ stop({Pid, Ref}) -> erlang:send(Pid, {Ref, done}). wait_db_updated({Pid, Ref}) -> + MonRef = erlang:monitor(process, Pid), erlang:send(Pid, {Ref, get_state}), receive - {state, Pid, State} -> State + {state, Pid, State} -> + erlang:demonitor(MonRef, [flush]), + State; + {'DOWN', MonRef, process, Pid, Reason} -> + throw({changes_feed_died, Reason}) end. receive_results(Workers, Acc0, Timeout) ->
