You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2016/07/18 09:29:20 UTC

[2/2] couch-replicator commit: updated refs/heads/master to bf636d3

Check if worker is alive for clean_mailbox

When a connection:close header is sent from the server, we handle it
by calling ibrowse:stop on the worker and release it from the worker
pool. But our clean_mailbox tries to clean the mailbox of this worker
when it's already dead, leading to a timeout that crashes the
changes_reader process and subsequently the replicator process. So
we check to ensure that the Worker is still alive before we call
ibrowse:stream_next.

BugzId:69053


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/bf636d30
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/bf636d30
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/bf636d30

Branch: refs/heads/master
Commit: bf636d3088e39e392517117e4e5ed4e22f8f7e34
Parents: 8283a30
Author: Tony Sun <to...@cloudant.com>
Authored: Mon Jun 27 18:54:43 2016 -0700
Committer: Robert Newson <rn...@apache.org>
Committed: Mon Jul 18 10:28:17 2016 +0100

----------------------------------------------------------------------
 src/couch_replicator_httpc.erl | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/bf636d30/src/couch_replicator_httpc.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_httpc.erl b/src/couch_replicator_httpc.erl
index 17e2091..266b922 100644
--- a/src/couch_replicator_httpc.erl
+++ b/src/couch_replicator_httpc.erl
@@ -222,16 +222,12 @@ clean_mailbox(_ReqId, 0) ->
 clean_mailbox({ibrowse_req_id, ReqId}, Count) when Count > 0 ->
     case get(?STREAM_STATUS) of
         {streaming, Worker} ->
-            ibrowse:stream_next(ReqId),
-            receive
-                {ibrowse_async_response, ReqId, _} ->
-                    clean_mailbox({ibrowse_req_id, ReqId}, Count - 1);
-                {ibrowse_async_response_end, ReqId} ->
+            case is_process_alive(Worker) of
+                true ->
+                    discard_message(ReqId, Worker, Count);
+                false ->
                     put(?STREAM_STATUS, ended),
                     ok
-                after 30000 ->
-                    exit(Worker, {timeout, ibrowse_stream_cleanup}),
-                    exit({timeout, ibrowse_stream_cleanup})
             end;
         Status when Status == init; Status == ended ->
             receive
@@ -248,6 +244,20 @@ clean_mailbox(_, Count) when Count > 0 ->
     ok.
 
 
+discard_message(ReqId, Worker, Count) ->
+    ibrowse:stream_next(ReqId),
+    receive
+        {ibrowse_async_response, ReqId, _} ->
+            clean_mailbox({ibrowse_req_id, ReqId}, Count - 1);
+        {ibrowse_async_response_end, ReqId} ->
+            put(?STREAM_STATUS, ended),
+            ok
+    after 30000 ->
+        exit(Worker, {timeout, ibrowse_stream_cleanup}),
+        exit({timeout, ibrowse_stream_cleanup})
+    end.
+
+
 maybe_retry(Error, Worker, #httpdb{retries = 0} = HttpDb, Params) ->
     report_error(Worker, HttpDb, Params, {error, Error});
 


Re: [2/2] couch-replicator commit: updated refs/heads/master to bf636d3

Posted by Alexander Shorin <kx...@gmail.com>.
Indeed, missed that. Thanks!
--
,,,^..^,,,


On Mon, Jul 18, 2016 at 2:20 PM, Robert Newson <rn...@apache.org> wrote:
> Two different processes. :)
>
> Sent from my iPhone
>
>> On 18 Jul 2016, at 10:51, Alexander Shorin <kx...@gmail.com> wrote:
>>
>>> On Mon, Jul 18, 2016 at 12:29 PM,  <rn...@apache.org> wrote:
>>> +        exit(Worker, {timeout, ibrowse_stream_cleanup}),
>>> +        exit({timeout, ibrowse_stream_cleanup})
>>
>> Why exit twice? Will the second cause any effect?
>>
>> --
>> ,,,^..^,,,

Re: [2/2] couch-replicator commit: updated refs/heads/master to bf636d3

Posted by Robert Newson <rn...@apache.org>.
Two different processes. :)

Sent from my iPhone

> On 18 Jul 2016, at 10:51, Alexander Shorin <kx...@gmail.com> wrote:
> 
>> On Mon, Jul 18, 2016 at 12:29 PM,  <rn...@apache.org> wrote:
>> +        exit(Worker, {timeout, ibrowse_stream_cleanup}),
>> +        exit({timeout, ibrowse_stream_cleanup})
> 
> Why exit twice? Will the second cause any effect?
> 
> --
> ,,,^..^,,,

Re: [2/2] couch-replicator commit: updated refs/heads/master to bf636d3

Posted by Alexander Shorin <kx...@gmail.com>.
On Mon, Jul 18, 2016 at 12:29 PM,  <rn...@apache.org> wrote:
> +        exit(Worker, {timeout, ibrowse_stream_cleanup}),
> +        exit({timeout, ibrowse_stream_cleanup})

Why exit twice? Will the second cause any effect?

--
,,,^..^,,,