anchor.diff:              exit(attachment_request_failed);
           ResponseCode == 500 ->
               % an error... log and retry
  -            ?LOG_INFO("retrying streaming attachment request due to 500 error: ~s", [Url]),
  +            ?LOG_INFO("retrying couch_rep attachment request in ~p " ++ 
  +                "seconds due to 500 response: ~s", [Pause/1000, Url]),
               Pid ! {self(), fail},
  +            catch ibrowse:stop_worker_process(Conn),
  +            timer:sleep(Pause),
               make_attachment_stub_receiver(Url, Headers, Name, Type, Length, 
  -                Retries - 1)
  +                Retries - 1, 2*Pause)
           end
       end.
   
  
positive.code:     do_http_request(Url, Action, Headers, []).
  
  do_http_request(Url, Action, Headers, JsonBody) ->
      do_http_request(Url, Action, Headers, JsonBody, 10).
  
  do_http_request(Url, Action, Headers, Body, Retries) when is_binary(Url) ->
      do_http_request(?b2l(Url), Action, Headers, Body, Retries);
  do_http_request(Url, Action, _Headers, _JsonBody, 0) ->
      ?LOG_ERROR("couch_rep HTTP ~p request failed after 10 retries: ~s", 
          [Action, Url]),
      exit({http_request_failed, ?l2b(["failed to replicate ", Url])});
  do_http_request(Url, Action, Headers, JsonBody, Retries) ->
      ?LOG_DEBUG("couch_rep HTTP ~p request: ~s", [Action, Url]),
      Body =
      case JsonBody of
  
negative.code:         ResponseCode >= 300, ResponseCode < 400 ->
              RedirectUrl = mochiweb_headers:get_value("Location", 
                  mochiweb_headers:make(ResponseHeaders)),
              do_http_request(RedirectUrl, Action, Headers, JsonBody, Retries-1,
                  Pause);
          ResponseCode >= 400, ResponseCode < 500 -> 
              ?JSON_DECODE(ResponseBody);        
          ResponseCode == 500 ->
              ?LOG_INFO("retrying couch_rep HTTP ~p request in ~p seconds " ++ 
                  "due to 500 error: ~s", [Action, Pause/1000, Url]),
              timer:sleep(Pause),
              do_http_request(Url, Action, Headers, JsonBody, Retries - 1, 2*Pause)
          end;
      {error, Reason} ->
          ?LOG_INFO("retrying couch_rep HTTP ~p request in ~p seconds due to " ++ 
              "{error, ~p}: ~s", [Action, Pause/1000, Reason, Url]),
          timer:sleep(Pause),
          do_http_request(Url, Action, Headers, JsonBody, Retries - 1, 2*Pause)
      end.
  
  ensure_full_commit(#http_db{uri=DbUrl, headers=Headers}) ->
  