couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [09/27] couch-replicator commit: updated refs/heads/windsor-merge to 75e5ba1
Date Wed, 06 Aug 2014 18:17:59 GMT
Fix a non-tail-recursive call that leaks memory

By recursing in the protected body of a try/catch we weren't properly
using tail recursion when restarting the changes feed. This leads to
mailbox accumulation of messages which slowly eats all RAM on the node.

BugzId: 20601


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/commit/44328a6c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/44328a6c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/44328a6c

Branch: refs/heads/windsor-merge
Commit: 44328a6cca9686334acc2932b3a46ccc780f2322
Parents: 20b837e
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Mon Jul 8 14:49:41 2013 -0500
Committer: Robert Newson <rnewson@apache.org>
Committed: Tue Jul 29 13:48:38 2014 +0100

----------------------------------------------------------------------
 src/couch_replicator.erl | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/44328a6c/src/couch_replicator.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator.erl b/src/couch_replicator.erl
index 3ef5e9c..bb81cf0 100644
--- a/src/couch_replicator.erl
+++ b/src/couch_replicator.erl
@@ -665,7 +665,7 @@ read_changes(Parent, StartSeq, Db, ChangesQueue, Options, Ts) ->
                         ok = gen_server:call(Parent, Msg, infinity)
                     end,
                     put(last_seq, Seq),
-                    read_changes(Parent, Seq, Db, ChangesQueue, Options, Ts + 1);
+                    throw(recurse);
                 _ ->
                     % This clause is unreachable today, but let's plan ahead
                     % for the future where we checkpoint against last_seq
@@ -675,7 +675,11 @@ read_changes(Parent, StartSeq, Db, ChangesQueue, Options, Ts) ->
                 end
             end, Options),
         couch_work_queue:close(ChangesQueue)
-    catch exit:{http_request_failed, _, _, _} = Error ->
+    catch
+        throw:recurse ->
+            LS = get(last_seq),
+            read_changes(Parent, LS, Db, ChangesQueue, Options, Ts+1);
+        exit:{http_request_failed, _, _, _} = Error ->
         case get(retries_left) of
         N when N > 0 ->
             put(retries_left, N - 1),


Mime
View raw message