Avoid deadlocking the httpc pool The multipart mime parsing code was getting into a state where it would orphan parsers that held onto pool connections. This just adds a monitor to make sure that the parser process dies when the parent dies normally without finishing reading the rest of the parser.
BugzID: 16751 Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/fa982654 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/fa982654 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/fa982654 Branch: refs/heads/1901-atomic-multipart-retries Commit: fa982654b10a8d79ea934c5d9b5cb91ff7998e45 Parents: 962ce08 Author: Paul J. Davis <[email protected]> Authored: Fri Feb 22 13:44:20 2013 -0600 Committer: Adam Kocoloski <[email protected]> Committed: Wed Oct 2 11:59:20 2013 -0400 ---------------------------------------------------------------------- .../src/couch_replicator_api_wrap.erl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/fa982654/src/couch_replicator/src/couch_replicator_api_wrap.erl ---------------------------------------------------------------------- diff --git a/src/couch_replicator/src/couch_replicator_api_wrap.erl b/src/couch_replicator/src/couch_replicator_api_wrap.erl index cd69e59..4aabe15 100644 --- a/src/couch_replicator/src/couch_replicator_api_wrap.erl +++ b/src/couch_replicator/src/couch_replicator_api_wrap.erl @@ -177,6 +177,20 @@ open_doc_revs(#httpdb{} = HttpDb, Id, Revs, Options, Fun, Acc) -> end), unlink(Self) end), + % If this process dies normally we can leave + % the Streamer process hanging around keeping an + % HTTP connection open. This is a bit of a + % hammer approach to making sure it releases + % that connection back to the pool. + spawn(fun() -> + Ref = erlang:monitor(process, Self), + receive + {'DOWN', Ref, process, Self, normal} -> + exit(Streamer, {streamer_parent_died, Self}); + {'DOWN', Ref, process, Self, _} -> + ok + end + end), receive {started_open_doc_revs, Ref} -> receive_docs_loop(Streamer, Fun, Id, Revs, Ref, Acc)
