Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/couch_replicator_httpc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ process_response({error, connection_closing}, Worker, HttpDb, Params, _Cb) ->
stop_and_release_worker(HttpDb#httpdb.httpc_pool, Worker),
throw({retry, HttpDb, Params});

process_response({error, {'EXIT',{normal,_}}}, _Worker, HttpDb, Params, _Cb) ->
process_response({error, req_timedout}, _Worker, HttpDb, Params, _Cb) ->
% ibrowse worker terminated because remote peer closed the socket
% -> not an error
throw({retry, HttpDb, Params});
Expand Down Expand Up @@ -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
Expand All @@ -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});

Expand Down