You are correct, it does need to be set to true there. Doh. Since I never hit the problem, I couldn't be sure I fixed it correctly.

-Damien


On Mar 16, 2009, at 5:39 PM, Adam Kocoloski wrote:

Hi Damien, I'm confused. Don't you need to set done=true in the handle_call for fin?

Adam

On Mar 16, 2009, at 5:26 PM, [email protected] wrote:

Author: damien
Date: Mon Mar 16 21:26:47 2009
New Revision: 755009

URL: http://svn.apache.org/viewvc?rev=755009&view=rev
Log:
Fix for occasional replication failure where replication would complete before before the caller had a chance to request the results. No tests, but this should fix this error that already occurs occasionally: {"error":"normal","reason":"{gen_server,call, [<0.228.0>,get_result,infinity]}"}

Modified:
  couchdb/trunk/src/couchdb/couch_rep.erl

Modified: couchdb/trunk/src/couchdb/couch_rep.erl
URL: 
http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep.erl?rev=755009&r1=755008&r2=755009&view=diff
= = = = = = = = = =====================================================================
--- couchdb/trunk/src/couchdb/couch_rep.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep.erl Mon Mar 16 21:26:47 2009
@@ -91,7 +91,8 @@
   stats,
   enum_pid,
   docs_buffer = [],
-    listeners = []
+    listeners = [],
+    done = false
}).


@@ -178,7 +179,8 @@
   },

   {ok, State}.
-
+handle_call(get_result, From, #state{listeners=L,done=true} = State) ->
+    {stop, normal, State#state{listeners=[From|L]}};
handle_call(get_result, From, #state{listeners=L} = State) ->
   {noreply, State#state{listeners=[From|L]}};

@@ -218,7 +220,13 @@

handle_call({fin, {LastSeq, RevsCount}}, {Pid,_}, #state{enum_pid=Pid} = State) ->
   ets:update_counter(State#state.stats, total_revs, RevsCount),
-    {stop, normal, ok, State#state{current_seq=LastSeq}}.
+    case State#state.listeners of
+    [] ->
+        % still waiting for the first listener to sen a request
+        {noreply, State#state{current_seq=LastSeq}};
+    _ ->
+        {stop, normal, ok, State#state{current_seq=LastSeq}}
+    end.

handle_cast({increment_update_seq, Seq}, State) ->
   couch_task_status:update("Processed source update #~p", [Seq]),
@@ -270,12 +278,8 @@
   ets:delete(Stats),
   close_db(Target),

-    case Listeners of
-    [Original|Rest] ->
-        %% reply to original requester
-        gen_server:reply(Original, {ok, NewRepHistory});
-    Rest -> ok
-    end,
+    [Original|Rest] = Listeners,
+    gen_server:reply(Original, {ok, NewRepHistory}),

%% maybe trigger another replication. If this replicator uses a local %% source Db, changes to that Db since we started will not be included in




Reply via email to