Skip to content

🐛 bug: retry addon: remove unnecessary sleep after last failed attempt#4060

Merged
ReneWerner87 merged 2 commits intogofiber:mainfrom
SadikSunbul:main
Feb 7, 2026
Merged

🐛 bug: retry addon: remove unnecessary sleep after last failed attempt#4060
ReneWerner87 merged 2 commits intogofiber:mainfrom
SadikSunbul:main

Conversation

@SadikSunbul
Copy link
Contributor

Description

This PR fixes a logic issue in the retry addon's ExponentialBackoff.Retry method: unnecessary sleep after the last failed attempt.

Previously, when all attempts failed, the code still called e.next() and time.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

  • What: The main loop was changed from for range e.MaxRetryCount to for i := 0; i < e.MaxRetryCount; i++. After each failed attempt we only call e.next() and time.Sleep(next) when i < e.MaxRetryCount-1 (i.e. when there will be another attempt).
  • Why: Once the last attempt has failed, there is no next try; sleeping only delays returning the error with no benefit. Total attempts and semantics are unchanged; only the redundant final sleep is removed.

Existing tests (e.g. “Unsuccessful function” with 5 attempts) still pass and now complete sooner when all attempts fail.

  • Benchmarks: N/A — logic fix only, no new benchmarks.
  • Documentation Update: No doc changes; behavior is corrected to match intended semantics.
  • Changelog/What's New: Bug fix for retry addon — remove unnecessary sleep after last failed attempt.
  • Migration Guide: Not needed; backward compatible.
  • API Alignment with Express: N/A.
  • API Longevity: No API change; same method signatures and public behavior.
  • Examples: Existing examples remain valid.

Type of change

  • Enhancement (improvement to existing features and functionality)
  • Code consistency (non-breaking change which improves code reliability and robustness)

Checklist

  • Conducted a self-review of the code.
  • Updated the documentation in the /docs/ directory — N/A for this fix.
  • Ensured that new and existing unit tests pass locally.
  • No new dependencies.
  • No new allocations; loop structure change is minimal.

@SadikSunbul SadikSunbul requested a review from a team as a code owner February 7, 2026 13:19
@welcome
Copy link

welcome bot commented Feb 7, 2026

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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 ExponentialBackoff.Retry method. It refines the retry loop to prevent an unneeded delay after the last attempt fails, ensuring that errors are propagated to the caller without superfluous waiting. This change optimizes the function's execution time in failure scenarios while maintaining its core retry behavior.

Highlights

  • Redundant Sleep Removal: The ExponentialBackoff.Retry method no longer performs an unnecessary time.Sleep after the final failed attempt, improving efficiency without altering retry logic.

🧠 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
  • addon/retry/exponential_backoff.go
    • Modified the retry loop from for range e.MaxRetryCount to for i := 0; i < e.MaxRetryCount; i++.
    • Introduced a conditional check if i < e.MaxRetryCount-1 to ensure e.next() and time.Sleep(next) are only called if further retry attempts are scheduled.
Activity
  • The author conducted a self-review of the code.
  • Existing unit tests have been verified and pass locally, completing sooner in failure scenarios.
  • No new dependencies or allocations were introduced.
  • Documentation updates were deemed unnecessary as the change is a logic fix.
  • The change is categorized as an enhancement and an improvement to code consistency.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ReneWerner87 ReneWerner87 added this to v3 Feb 7, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2026

Walkthrough

Replaces 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

Cohort / File(s) Summary
Exponential Backoff implementation
addon/retry/exponential_backoff.go
Replaced range-based loop with for i := 0; i < MaxRetryCount; i++ and made backoff sleep conditional so it does not run after the final attempt (i < MaxRetryCount-1).
Exponential Backoff tests
addon/retry/exponential_backoff_test.go
Added Test_ExponentialBackoff_Retry_NoSleepAfterLastAttempt to assert no sleep occurs after the last retry when all attempts fail.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • sixcolors
  • gaby
  • ReneWerner87

Poem

"🐇 I hopped each retry, counted every try,
No pause on the last — swift was my sigh.
With indexed leaps I bound ahead,
Leaving sleepy waits for others instead. ✨"

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: removing unnecessary sleep after the last failed retry attempt in the retry addon.
Description check ✅ Passed The description covers the problem, the solution, changes introduced, and completes the provided checklist; all major sections are addressed with appropriate detail.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.05%. Comparing base (8b5d061) to head (9d1665b).
⚠️ Report is 4 commits behind head on main.

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              
Flag Coverage Δ
unittests 91.05% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@ReneWerner87 ReneWerner87 merged commit b4984af into gofiber:main Feb 7, 2026
23 checks passed
@welcome
Copy link

welcome bot commented Feb 7, 2026

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

@github-project-automation github-project-automation bot moved this to Done in v3 Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants