Skip to content

feat: honor Retry-After header in BackOffHandler - #3204

Open
spiccoaura wants to merge 2 commits into
googleapis:mainfrom
spiccoaura:feat/honor-retry-after
Open

feat: honor Retry-After header in BackOffHandler#3204
spiccoaura wants to merge 2 commits into
googleapis:mainfrom
spiccoaura:feat/honor-retry-after

Conversation

@spiccoaura

Copy link
Copy Markdown

Description

This PR addresses the issue where BackOffHandler doesn't honor the Retry-After header sent by Google APIs during rate-limiting scenarios (HTTP 429).

Previously, the handler strictly relied on the standard exponential back-off algorithm. Now, it extracts either the delta interval (seconds) or the absolute target date from the Retry-After header if present, falling back to the standard exponential algorithm if the header is missing or invalid.

Changes

  • Modified BackOffHandler.HandleResponseAsync to parse args.Response.Headers.RetryAfter.
  • Updated the private HandleAsync method signature to pass down the optional parsed TimeSpan.
  • Added two target unit tests in ConfigurableMessageHandlerTest covering both Delta and Date header configurations.

All 118 tests pass successfully across both target frameworks (net8.0 and net462).
Closes #2715

@spiccoaura
spiccoaura requested a review from a team as a code owner July 10, 2026 10:08

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

Copy link
Copy Markdown

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 introduces support for honoring the HTTP Retry-After header (both relative delay and absolute date/time formats) in the BackOffHandler, along with corresponding unit tests. The review feedback highlights an issue where a zero or negative Retry-After delay (which can occur due to clock skew or immediate retry instructions) incorrectly falls back to the standard exponential back-off. It is recommended to clamp negative delays to TimeSpan.Zero and respect the immediate retry instruction instead of falling back.

Comment thread Src/Support/Google.Apis.Core/Http/BackOffHandler.cs Outdated
@amanda-tarafa amanda-tarafa self-assigned this Jul 10, 2026
@amanda-tarafa amanda-tarafa added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jul 10, 2026
@amanda-tarafa

Copy link
Copy Markdown
Contributor

do not merge until we have bandwidth to review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge Indicates a pull request not ready for merge, due to either quality or timing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BackOffHandler to honor retryAfter value in case of rateLimitExceeded

2 participants