anchor.diff:      %% wait for headers to ensure that we have a 200 status code
       %% this is where we follow redirects etc
       Pid ! {self(), gimme_status}, 
  -    receive {Pid, {status, StreamStatus, StreamHeaders}} -> 
  +    receive
  +    {'EXIT', Pid, attachment_request_failed} ->
  +        make_attachment_stub_receiver(Url, Headers, Name, Type, Length, Retries-1);
  +    {Pid, {status, StreamStatus, StreamHeaders}} -> 
           ?LOG_DEBUG("streaming attachment Status ~p Headers ~p",
               [StreamStatus, StreamHeaders]),
           
  
positive.code:         stats = Stats
      } = State,
      
      {ok, Errors} = update_docs(Target, lists:flatten(Buffer), [], replicated_changes),
      dump_update_errors(Errors),
      ets:update_counter(Stats, doc_write_failures, length(Errors)),
      ets:update_counter(Stats, docs_written, lists:flatlength(Buffer) -
              length(Errors)),
      
      couch_task_status:update("Finishing"),
      
  
negative.code:     case should_flush(lists:flatlength([Docs|Buffer])) of
          true ->
              Docs2 = lists:flatten([Docs|Buffer]),
              try update_docs(Target, Docs2, [], replicated_changes) of
              {ok, Errors} ->
                  dump_update_errors(Errors),
                  ets:update_counter(Stats, doc_write_failures, length(Errors)),
                  ets:update_counter(Stats, docs_written, length(Docs2) -
                          length(Errors)),
                  {ok, _, Ctxt} = do_checkpoint(Source, Target, Context, Seq, Stats),
                  {[], Ctxt}
              catch
              throw:attachment_write_failed ->
                  ?LOG_ERROR("attachment request failed during write to disk", []),
                  exit({internal_server_error, replication_link_failure})
              end;
          false ->
              {[Docs | Buffer], Context}
      end,
  