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

graph: fix backoff overflow #4421

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

YaroShkvorets
Copy link
Contributor

This PR fixes an issue with backoff left shift overflow #4420
Also adds tests for that struct.

Copy link
Collaborator

@lutter lutter left a comment

Choose a reason for hiding this comment

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

Nice find!

@@ -33,7 +33,7 @@ impl ExponentialBackoff {
}

pub fn delay(&self) -> Duration {
let mut delay = self.base.saturating_mul(1 << self.attempt);
let mut delay = self.base.saturating_mul(1u32 << self.attempt.min(31));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be better to make sure that next_attempt never increments self.attempt to more than 31. We can also do the min here in addition, but I think we should also clamp self.attempt to 31 explicitly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought it would be better to let it increment to have a sense how many total attempts there were, i.e. for logging.

Copy link
Collaborator

Choose a reason for hiding this comment

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

True. That makes sense

@lutter lutter merged commit f8d0143 into graphprotocol:master Mar 6, 2023
@YaroShkvorets YaroShkvorets deleted the fix/backoff_overflow branch March 6, 2023 18:52
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.

2 participants