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

External Scaler: fix wrong calculation of retry backoff duration #2416

Merged
merged 3 commits into from
Jan 4, 2022
Merged

External Scaler: fix wrong calculation of retry backoff duration #2416

merged 3 commits into from
Jan 4, 2022

Conversation

yusank
Copy link
Contributor

@yusank yusank commented Dec 27, 2021

Signed-off-by: yusank yusankurban@gmail.com

There a wrong calculation logic when calculate next retry backoff duration in external_scalers.go:L216

Original code:

// retry on error from runWithLog() starting by 2 sec backing off * 2 with a max of 1 minute
retryDuration := time.Second * 2
// the caller of this function needs to ensure that they call Stop() on the resulting
// timer, to release background resources.
retryBackoff := func() *time.Timer {
    tmr := time.NewTimer(retryDuration)
    // HERE IS THE PROBLEM
    // Should multiply with `2`, not `time.Second * 2`. 
    // Otherwise it will be always backoff 1m, instead of [2s,4s,8s,16s,32s,1m,1m...]
    retryDuration *= time.Second * 2
    if retryDuration > time.Minute*1 {
	retryDuration = time.Minute * 1
    }
    return tmr
}

after fix:

// retry on error from runWithLog() starting by 2 sec backing off * 2 with a max of 1 minute
retryDuration := time.Second * 2
// the caller of this function needs to ensure that they call Stop() on the resulting
// timer, to release background resources.
retryBackoff := func() *time.Timer {
    tmr := time.NewTimer(retryDuration)
    retryDuration *= 2
    if retryDuration > time.Minute*1 {
	retryDuration = time.Minute * 1
    }
    return tmr
}

Checklist

  • Commits are signed with Developer Certificate of Origin (DCO - learn more)
  • Changelog has been updated

Fixes #

Signed-off-by: yusank <yusankurban@gmail.com>
@yusank yusank requested a review from a team as a code owner December 27, 2021 10:18
@zroubalik zroubalik changed the title fix: wrong calculation of retry backoff duraion External Scaler: fix wrong calculation of retry backoff duraion Jan 3, 2022
@zroubalik zroubalik changed the title External Scaler: fix wrong calculation of retry backoff duraion External Scaler: fix wrong calculation of retry backoff duration Jan 3, 2022
Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Could you please update the Changelog as well? (Improvements section). Thanks

@zroubalik zroubalik added this to the v2.6.0 milestone Jan 3, 2022
@yusank
Copy link
Contributor Author

yusank commented Jan 4, 2022

Good catch! Could you please update the Changelog as well? (Improvements section). Thanks

Ok, I will update it now.

@zroubalik zroubalik merged commit 1fd6866 into kedacore:main Jan 4, 2022
alex60217101990 pushed a commit to dysnix/keda that referenced this pull request Jan 10, 2022
…acore#2416)

Signed-off-by: yusank <yusankurban@gmail.com>
Signed-off-by: alex60217101990 <alex6021710@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants