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

exponential backoff is not applied #358

Closed
luckpoint opened this issue Jul 14, 2022 · 1 comment · Fixed by #386
Closed

exponential backoff is not applied #358

luckpoint opened this issue Jul 14, 2022 · 1 comment · Fixed by #386
Labels
bug This points to a verified bug in the code

Comments

@luckpoint
Copy link

Describe the problem

I exerted the related code from ruby-auth0/lib/auth0/mixins/httpproxy.rb

DEAFULT_RETRIES = 3
MAX_ALLOWED_RETRIES = 10
MAX_REQUEST_RETRY_JITTER = 250
MAX_REQUEST_RETRY_DELAY = 1000
MIN_REQUEST_RETRY_DELAY = 100

sleep_timer = lambda do |attempt|
  wait = 1000 * 2**attempt # Exponential delay with each subsequent request attempt.
  wait += rand(wait..wait+MAX_REQUEST_RETRY_JITTER) # Add jitter to the delay window.
  wait = [MAX_REQUEST_RETRY_DELAY, wait].min # Cap delay at MAX_REQUEST_RETRY_DELAY.
  wait = [MIN_REQUEST_RETRY_DELAY, wait].max # Ensure delay is no less than MIN_REQUEST_RETRY_DELAY.
  wait / 1000.to_f.round(2) # convert ms to seconds
end

MAX_ALLOWED_RETRIES.times { |attempt|
  p sleep_timer.call(attempt)
}

# => 1.0
# => 1.0
# => 1.0
# => 1.0
# => 1.0
# => 1.0
# => 1.0
# => 1.0
# => 1.0
# => 1.0

exponential backoff is not applied and wait is always 1.0.

What was the expected behavior?

if I comment some codes out, it will work as commented.

DEAFULT_RETRIES = 3
MAX_ALLOWED_RETRIES = 10
MAX_REQUEST_RETRY_JITTER = 250
MAX_REQUEST_RETRY_DELAY = 1000
MIN_REQUEST_RETRY_DELAY = 100

sleep_timer = lambda do |attempt|
  wait = 1000 * 2**attempt # Exponential delay with each subsequent request attempt.
  wait += rand(wait..wait+MAX_REQUEST_RETRY_JITTER) # Add jitter to the delay window.
# wait = [MAX_REQUEST_RETRY_DELAY, wait].min # Cap delay at MAX_REQUEST_RETRY_DELAY.
# wait = [MIN_REQUEST_RETRY_DELAY, wait].max # Ensure delay is no less than MIN_REQUEST_RETRY_DELAY.
  wait / 1000.to_f.round(2) # convert ms to seconds
end

MAX_ALLOWED_RETRIES.times { |attempt|
  p sleep_timer.call(attempt)
}

# => 2.144
# => 4.171
# => 8.135
# => 16.049
# => 32.177
# => 64.19
# => 128.167
# => 256.134
# => 512.122
# => 1024.223

exponential backoff is applied.

@stevehobbsdev stevehobbsdev added the bug This points to a verified bug in the code label Aug 2, 2022
@stevehobbsdev
Copy link
Contributor

Thanks for the report @luckpoint, and thanks for your patience. Let me dive into it this week and make some changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This points to a verified bug in the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants