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

Integer overflow on calcDelay #23523

Open
bcho opened this issue Sep 30, 2024 · 0 comments
Open

Integer overflow on calcDelay #23523

bcho opened this issue Sep 30, 2024 · 0 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Event Hubs Service Bus

Comments

@bcho
Copy link
Member

bcho commented Sep 30, 2024

Opening an issue for the other implementations in the codebase.

For the other cases can you please open issues? We'll let their owners clean them up.

Originally posted by @jhendrixMSFT in #23441 (comment)

Implementations seeing the same overflow bug:

func calcDelay(o exported.RetryOptions, try int32) time.Duration {
if try == 0 {
return 0
}
pow := func(number int64, exponent int32) int64 { // pow is nested helper function
var result int64 = 1
for n := int32(0); n < exponent; n++ {
result *= number
}
return result
}
delay := time.Duration(pow(2, try)-1) * o.RetryDelay
// Introduce some jitter: [0.0, 1.0) / 2 = [0.0, 0.5) + 0.8 = [0.8, 1.3)
delay = time.Duration(delay.Seconds() * (rand.Float64()/2 + 0.8) * float64(time.Second)) // NOTE: We want math/rand; not crypto/rand
if delay > o.MaxRetryDelay {
delay = o.MaxRetryDelay
}
return delay
}

func calcDelay(o exported.RetryOptions, try int32) time.Duration {
if try == 0 {
return 0
}
pow := func(number int64, exponent int32) int64 { // pow is nested helper function
var result int64 = 1
for n := int32(0); n < exponent; n++ {
result *= number
}
return result
}
delay := time.Duration(pow(2, try)-1) * o.RetryDelay
// Introduce some jitter: [0.0, 1.0) / 2 = [0.0, 0.5) + 0.8 = [0.8, 1.3)
delay = time.Duration(delay.Seconds() * (rand.Float64()/2 + 0.8) * float64(time.Second)) // NOTE: We want math/rand; not crypto/rand
if delay > o.MaxRetryDelay {
delay = o.MaxRetryDelay
}
return delay

@github-actions github-actions bot added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Sep 30, 2024
@jhendrixMSFT jhendrixMSFT added Service Bus Event Hubs Client This issue points to a problem in the data-plane of the library. labels Oct 1, 2024
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. Event Hubs Service Bus
Projects
None yet
Development

No branches or pull requests

3 participants