🐛 bug: retry addon: remove unnecessary sleep after last failed attempt#4060
🐛 bug: retry addon: remove unnecessary sleep after last failed attempt#4060ReneWerner87 merged 2 commits intogofiber:mainfrom
Conversation
|
Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
Summary of ChangesHello @SadikSunbul, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a minor but impactful bug in the retry addon's Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
WalkthroughReplaces the range-based loop in ExponentialBackoff.Retry with an indexed for loop and prevents sleeping after the final retry attempt; adds a test ensuring no sleep occurs after the last failed attempt. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a logic issue where an unnecessary time.Sleep was called after the final failed attempt in the retry loop. The change to use a standard indexed for loop and conditionally sleep is a clear and effective solution. This improves the efficiency by removing the redundant delay when all retries are exhausted. The change is well-described and correct. Great work!
There was a problem hiding this comment.
Pull request overview
Fixes retry behavior in addon/retry by removing an unnecessary backoff sleep after the final failed retry attempt, so errors propagate immediately once retries are exhausted.
Changes:
- Replaced the integer-range loop with an index-based loop in
ExponentialBackoff.Retry. - Added a guard to only compute the next backoff interval and sleep when another retry will occur.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4060 +/- ##
==========================================
- Coverage 91.09% 91.05% -0.04%
==========================================
Files 119 119
Lines 11203 11204 +1
==========================================
- Hits 10205 10202 -3
- Misses 631 635 +4
Partials 367 367
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
Description
This PR fixes a logic issue in the retry addon's
ExponentialBackoff.Retrymethod: unnecessary sleep after the last failed attempt.Previously, when all attempts failed, the code still called
e.next()andtime.Sleep(next)after the final failure before returning the error. Since no further attempt would be made, this sleep was redundant and only added delay before propagating the error to the caller. The change removes that redundant sleep while keeping the number of attempts and success/failure behavior unchanged.Changes introduced
Avoid sleeping after the last attempt
for range e.MaxRetryCounttofor i := 0; i < e.MaxRetryCount; i++. After each failed attempt we only calle.next()andtime.Sleep(next)wheni < e.MaxRetryCount-1(i.e. when there will be another attempt).Existing tests (e.g. “Unsuccessful function” with 5 attempts) still pass and now complete sooner when all attempts fail.
Type of change
Checklist
/docs/directory — N/A for this fix.