Skip to content

Commit

Permalink
Clean up connections which received a 413 response.
Browse files Browse the repository at this point in the history
Connections which received a 413 response might be dirty so to be safe, clean
them up by killing them, waiting for them to die, then return them to the
connection pool.

Issue apache#574
  • Loading branch information
nickva committed Jul 28, 2017
1 parent 66a199d commit 72b988b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/couch_replicator/src/couch_replicator_httpc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ process_response({ok, Code, Headers, Body}, Worker, HttpDb, Params, Callback) ->
Json ->
?JSON_DECODE(Json)
end,
Callback(Ok, Headers, EJson);
Ret = Callback(Ok, Headers, EJson),
maybe_stop_worker(Ok, Worker, HttpDb#httpdb.httpc_pool),
Ret;
R when R =:= 301 ; R =:= 302 ; R =:= 303 ->
backoff_success(HttpDb, Params),
do_redirect(Worker, R, Headers, HttpDb, Params, Callback);
Expand Down Expand Up @@ -191,6 +193,7 @@ process_stream_response(ReqId, Worker, HttpDb, Params, Callback) ->
ibrowse:stream_next(ReqId),
try
Ret = Callback(Ok, Headers, StreamDataFun),
maybe_stop_worker(Ok, Worker, HttpDb#httpdb.httpc_pool),
Ret
catch
throw:{maybe_retry_req, connection_closed} ->
Expand Down Expand Up @@ -221,6 +224,15 @@ process_stream_response(ReqId, Worker, HttpDb, Params, Callback) ->
end.


% Some error responses like 413 might leave the worker socket connection in a
% dirty state. To be safe make sure to stop that worker, wait for it to die
% and return it to the pool.
maybe_stop_worker(413, Worker, Pool) ->
stop_and_release_worker(Pool, Worker);
maybe_stop_worker(_Code, _Worker, _Pool) ->
ok.


% Only streaming HTTP requests send messages back from
% the ibrowse worker process. We can detect that based
% on the ibrowse_req_id format. This just drops all
Expand Down

0 comments on commit 72b988b

Please sign in to comment.