summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2013-02-22 13:44:20 -0600
committerAdam Kocoloski <adam@cloudant.com>2013-10-02 11:59:20 -0400
commitfa982654b10a8d79ea934c5d9b5cb91ff7998e45 (patch)
treefb8f6641548e7a66111fa2bfc5649c7b94fc2eb4
parent962ce087bfac80e2d721b679fee4fe1568a4d362 (diff)
downloadcouchdb-fa982654b10a8d79ea934c5d9b5cb91ff7998e45.tar.gz
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
-rw-r--r--src/couch_replicator/src/couch_replicator_api_wrap.erl14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/couch_replicator/src/couch_replicator_api_wrap.erl b/src/couch_replicator/src/couch_replicator_api_wrap.erl
index cd69e590e..4aabe15a1 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)