Github user nickva commented on a diff in the pull request:

    
https://github.com/apache/couchdb-couch-replicator/pull/40#discussion_r64961411
  
    --- Diff: src/couch_replicator_httpc.erl ---
    @@ -251,18 +257,42 @@ clean_mailbox(_, Count) when Count > 0 ->
     maybe_retry(Error, Worker, #httpdb{retries = 0} = HttpDb, Params) ->
         report_error(Worker, HttpDb, Params, {error, Error});
     
    +%% For 429 errors, we perform an exponential backoff up to 250 * 2^15
    +%% times, or roughly 2.17 hours. Since the #httpd.retries is initialized
    +%% to 10 and we need 15, we use the Wait time as a timeout/failure end.
    +maybe_retry(backoff, Worker, #httpdb{wait = Wait} = HttpDb, Params) ->
    +    ok = timer:sleep(random:uniform(Wait)),
    +    Wait2 = Wait*2,
    +    case Wait2 of
    +        W0 when W0 >= 512000 -> % Past 8 min, we log retries
    +            log_retry_error(Params, HttpDb, Wait, "429 Retry");
    +        W1 when W1 > ?MAX_BACKOFF_WAIT ->
    +            report_error(Worker, HttpDb, Params, {error,
    +                "429 Retry Timeout"});
    +        _ ->
    +            NewWait = erlang:min(Wait2, ?MAX_BACKOFF_WAIT),
    +            NewHttpDb = HttpDb#httpdb{wait = NewWait},
    +            throw({retry, NewHttpDb, Params})
    +    end;
    +
     maybe_retry(Error, _Worker, #httpdb{retries = Retries, wait = Wait} = 
HttpDb,
         Params) ->
    -    Method = string:to_upper(atom_to_list(get_value(method, Params, get))),
    -    Url = couch_util:url_strip_password(full_url(HttpDb, Params)),
    -    couch_log:notice("Retrying ~s request to ~s in ~p seconds due to error 
~s",
    -        [Method, Url, Wait / 1000, error_cause(Error)]),
    -    ok = timer:sleep(Wait),
    +    log_retry_error(Params, HttpDb, Wait, Error),
    +    % This is so that a long backoff time is not used to ensure
    +    % backwards compatibility.
    +    ok = timer:sleep(erlang:min(Wait, ?MAX_WAIT)),
         Wait2 = erlang:min(Wait * 2, ?MAX_WAIT),
    --- End diff --
    
    Let's randomize this as well, it avoids global synchronization (having all 
replication back-off with the same schedule).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to