Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The first delay of DelegateBackoff and ExponentialBackoff is always zero. #30

Closed
yowu opened this issue Sep 18, 2020 · 2 comments
Closed
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@yowu
Copy link
Contributor

yowu commented Sep 18, 2020

Let's take look at an example

 // use a ConstantBackoff
 const constDelayRetry = Policy.handleAll()
    .retry()
    .attempts(3)
    .backoff(new ConstantBackoff(10, 3));

  constDelayRetry.onRetry(({ delay }) => console.log('delay for next call: ', delay));
  await constDelayRetry.execute(() => {
    throw new Error('exception');
  });

// use a DelegateBackoff
  const delegatedDelayPolicy = Policy.handleAll()
    .retry()
    .attempts(3)
    .backoff(new DelegateBackoff(() => 10));

  delegatedDelayPolicy.onRetry(({ delay }) => console.log('delay for next call: ', delay));
  await delegatedDelayPolicy.execute(() => {
    throw new Error('exception');
  });

The output looks like

delay for next call:  10
delay for next call:  10
delay for next call:  10
delay for next call:  0
delay for next call:  10
delay for next call:  10

Conceptually, I would expect all delays are 10, but unfortunately, the first delay of DelegateBackoff is always 0.
Looks like the ExponentialBackoff has the same problem.

But Polly doesn't has such problem.
It looks like RetryPolicy.execute should adjust the logic to backoff.next() first then do the delay.

@connor4312
Copy link
Owner

Thanks for the issue, I would be happy to take a PR, otherwise I can fix this in a couple days.

@connor4312
Copy link
Owner

Fixed in the linked PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants