Skip to content

fix(httpclient): preserve failover with fixed retry backoff - #7777

Merged
Aias00 merged 1 commit into
apache:masterfrom
lymerin:7752
Oct 17, 2026
Merged

Aias00 merged 1 commit into
apache:masterfrom
lymerin:7752

Conversation

@lymerin

@lymerin lymerin commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #7752

Problem

With retryStrategy=failover and retryBackOffSpec=fixed, the fixed strategy bypasses upstream selection and resubscribes to the original request. Connection failures therefore retry the same upstream, while the 5xx failover signal is rejected by the fixed strategy’s exception filter and receives no retry.

Impact

GET requests fail despite an available healthy standby because configuring fixed backoff disables the requested failover behavior.

Changes

Reuse the existing failover flow for fixed retries, waiting two seconds before selecting and sending to another upstream. Allow the existing 5xx failover signal alongside transient network failures, while retaining the GET restriction, retry budget, and timeout handling.

Add regression coverage through the public plugin entry point for both reported failures, retry eligibility, and successive failover across distinct upstreams.

Validation

  • HTTP client module: 66 tests passed, zero failures or errors.
  • Checkstyle and Apache RAT passed.

Non-blocking note

FixedRetryStrategy reuses a package-private failover helper in DefaultRetryStrategy. This introduces coupling between the two strategies, but keeps upstream selection in one place without composing two retry policies. A separate failover executor is not needed for this fix; the existing flow is reused to keep the change focused on #7752.

Checklist

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM overall — the refactor is behaviour-preserving for DefaultRetryStrategy and the new branch fixes the reported dead end (failover + fixed backoff used to retry the same upstream and then reject the 5xx failover signal). I verified the parts that are easy to get wrong.

What I checked

  • Timeout budget: RetryTimeoutUtils.totalTimeout(duration, retryTimes, BACKOFF) = duration * (retries + 1) + backoff * retries, which is exactly the worst case of this pipeline (one 2 s delay plus one duration-bounded attempt per retry). The 2 s wait cannot starve the last attempt.
  • The extraction keeps the nesting semantics of the old resend for-loop: each iteration still wraps the previous one in onErrorResume, the shared exclude set still accumulates every attempted URI, and the terminal onErrorMap(ShenyuException -> 503) now sits outside the loop in both strategies.
  • Mono.delay hops to the parallel scheduler, but the non-failover fixed path already did that via Retry.fixedDelay, so no new thread-affinity assumption is introduced.
  • Constants.RETRY_STRATEGY is populated by DividePlugin, and shouldFailover gates ShenyuUpstreamStatusException on the same attribute, so the branch is live and the extra filter term is consistent rather than redundant-by-accident.

One behaviour change worth pinning down (please address before merge)

With retryStrategy=failover and a single-upstream selector, the old fixed path retried the same URI after 2 s. The new path excludes the only upstream, finds no candidate, and returns 503 CANNOT_FIND_HEALTHY_UPSTREAM_URL_AFTER_FAILOVER without using the retry budget. For one-standby-only or single-target divide selectors that is a functional regression against the fixed spec, even though it matches how the pre-existing default failover spec already behaves.

Two acceptable resolutions, your call:

  1. Keep it as is (consistent with failover semantics) and add a test asserting the 503 so the behaviour is intentional and documented in the release notes; or
  2. Fall back to retrying the original URI after the backoff when upstreamList is empty, which preserves fixed semantics and still fails over when a standby exists.

Today neither is covered: testFixedFailoverRetriesAcrossDistinctUpstreams always has a standby, and nothing exercises retryTimes = 0 through the new branch.

Non-blocking

  1. FixedRetryStrategy constructing new DefaultRetryStrategy<>(...) per request to reach a package-private executeFailover couples two strategies and allocates on the hot path. Given you already weighed this in the PR body, I'm fine with it for the fix; a follow-up extraction (FailoverExecutor with the delay + filter as parameters) would make the next strategy much cheaper to add.
  2. throwable instanceof ShenyuUpstreamStatusException does not unwrap causes, unlike isTransientFailure. That is correct for the current throw sites, but if recordOutcome ever starts wrapping the upstream status, the 5xx failover signal would silently stop being retried. A one-line comment ("thrown unwrapped by the client plugins") would lock the assumption down.

CI is green including pr_build, and the regression tests go through the public plugin entry point — thank you for that, it is what made this reviewable.

return response.retryWhen(retrySpec)
Mono<R> retriedResponse;
if (RetryEnum.FAILOVER.getName().equals(exchange.getAttribute(Constants.RETRY_STRATEGY))) {
retriedResponse = new DefaultRetryStrategy<>(httpClientPlugin).executeFailover(response, exchange, duration, retryTimes, BACKOFF,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This branch changes one observable behaviour: with a single-upstream selector the only candidate is excluded, so the retry budget is unused and the caller gets 503 CANNOT_FIND_HEALTHY_UPSTREAM_URL_AFTER_FAILOVER, where the old fixed path retried the same URI after 2s. Either pin it with a test (so it is clearly intentional + a release-note line) or fall back to retrying the original URI when no standby exists. Nothing currently covers the empty-candidate case (details in the review body).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the detailed review!

You're right, I overlooked the single-upstream case. I initially approached this with RPC-style failover in mind, focusing on switching to another upstream after a failure, but missed the case where no alternative is available.

I agree that option 2 is more appropriate here, as it preserves the existing fixed retry behavior without sacrificing failover when another upstream is available.

I'll address this tomorrow and add regression tests for the single-upstream case and retryTimes = 0.

Thanks again for catching this!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for merging!

Just to clarify, the single-upstream fallback discussed in the review hasn't been implemented in this PR yet.

I had planned to address it tomorrow as mentioned earlier. Would you prefer a follow-up PR implementing option 2, or do you consider the current failover behavior acceptable as-is?

@Aias00
Aias00 merged commit e9e15a3 into apache:master Oct 17, 2026
29 checks passed
@Aias00 Aias00 added this to the 2.7.2 milestone Nov 13, 2026
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.

[BUG] Fixed HTTP backoff bypasses the configured failover retry strategy

2 participants