Repository navigation
fix(httpclient): preserve failover with fixed retry backoff - #7777
Conversation
Aias00
left a comment
There was a problem hiding this comment.
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 oneduration-bounded attempt per retry). The 2 s wait cannot starve the last attempt. - The extraction keeps the nesting semantics of the old
resendfor-loop: each iteration still wraps the previous one inonErrorResume, the sharedexcludeset still accumulates every attempted URI, and the terminalonErrorMap(ShenyuException -> 503)now sits outside the loop in both strategies. Mono.delayhops to the parallel scheduler, but the non-failover fixed path already did that viaRetry.fixedDelay, so no new thread-affinity assumption is introduced.Constants.RETRY_STRATEGYis populated byDividePlugin, andshouldFailovergatesShenyuUpstreamStatusExceptionon 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:
- 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
- Fall back to retrying the original URI after the backoff when
upstreamListis 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
FixedRetryStrategyconstructingnew DefaultRetryStrategy<>(...)per request to reach a package-privateexecuteFailovercouples 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 (FailoverExecutorwith the delay + filter as parameters) would make the next strategy much cheaper to add.throwable instanceof ShenyuUpstreamStatusExceptiondoes not unwrap causes, unlikeisTransientFailure. That is correct for the current throw sites, but ifrecordOutcomeever 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, |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
Fixes #7752
Problem
With
retryStrategy=failoverandretryBackOffSpec=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
Non-blocking note
FixedRetryStrategyreuses a package-private failover helper inDefaultRetryStrategy. 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:
./mvnw clean install -Dmaven.javadoc.skip=true.