Repository navigation
[type:fix] retry network failures with exponential backoff - #7201
Conversation
Aias00
left a comment
There was a problem hiding this comment.
Approving — this removes a filter that made the exponential-backoff strategy effectively dead code for real failures.
.filter(t -> t instanceof IllegalStateException) meant the retry only ever fired for IllegalStateException, i.e. essentially never for genuine network faults (IOException, connection reset, timeouts). With transientErrors(true) already configured, dropping the filter lets the spec do what its name promises: retry transient network failures with backoff and jitter.
Verified:
- The retry budget is still bounded — the rewritten test asserts exactly
retryTimes + 1invocations (1 initial + 3 retries), sotransientErrors(true)is not turning this into an infinite retry loop. onRetryExhaustedThrowstill converts exhaustion intoIllegalStateException("Retry limit exceeded"), so callers see the same terminal error type as before.- Switching the test to
StepVerifier.withVirtualTimekeeps the suite fast despite the backoff delays.
One thing to keep an eye on (non-blocking, possibly covered by #7180): with the filter gone, retries now apply to all methods, not just idempotent GETs. Reactor's "transient" classification is about the error, not the HTTP method, so a POST that fails after the server already began processing could be replayed. If that matters, an additional exchange.getRequest().getMethod() guard would be worth adding — flagging it here for visibility rather than as a blocker.
sunnysabor
left a comment
There was a problem hiding this comment.
The removed filter makes this strategy retry every throwable for every HTTP method. That includes permanent response failures (for example, a 4xx surfaced as WebClientResponseException) and non-idempotent POST/PUT requests whose server may already have processed the request before the connection failed. Exponential backoff limits retry rate but does not prevent duplicate writes or retries of permanent failures.
This is especially relevant now that the adjacent fixed-delay strategy was changed in #7180 to retry only explicit transient network/timeout failures and only for GET. Please apply the same safety policy here (or otherwise document/configure the intended semantics), and add regression coverage showing a transient GET is retried while a permanent error and a non-GET request are not. The current IOException-only test does not exercise those boundaries.
Aias00
left a comment
There was a problem hiding this comment.
The exponential retry spec has no exception filter or HTTP method guard, so it retries permanent errors and can repeat non-idempotent requests. Exhaustion also replaces the original error semantics. Please limit retries to explicit transient network failures and safe/idempotent methods, and add negative tests for permanent errors and POST requests.
|
Hi @dengliming, this PR currently has merge conflicts with the |
Aias00
left a comment
There was a problem hiding this comment.
Summary
Re-review at current head. The retry strategy now scopes retries to transient network failures on safe methods, and exhaustion preserves the original error.
Resolved
ExponentialRetryBackoffStrategy.initDefaultBackoff(exchange, retryTimes)filter is nowHttpMethod.GET.equals(method) && isTransientFailure(throwable);isTransientFailurewalks the cause chain forTimeoutException,ConnectTimeoutException,ReadTimeoutException,ConnectException,SocketTimeoutException, andPrematureCloseException.onRetryExhaustedThrownow rethrowsretrySignal.failure()instead of wrapping inIllegalStateException("Retry limit exceeded")— the original error semantics are preserved.- Negative tests added:
testExponentialStrategyDoesNotRetryUnsafeRequestsOrPermanentFailures(GET + 400 permanent; POST/PUT even on timeout → no retry), plus a positive retry test that assertsretryTimes + 1attempts.
Verification
CI: pr_build, Analyze (java), check-license-header, rat_check, scope, sql-matrix all pass.
Conclusion
APPROVE.
Fixes #6636.\n\nRemove the IllegalStateException-only filter so exponential backoff applies to actual outbound failures. The regression test uses an IOException and verifies all configured retry attempts.\n\nTests:
./mvnw -q -pl shenyu-plugin/shenyu-plugin-httpclient -am -DskipTests=false -Dcheckstyle.skip=false -Dtest=RetryStrategyTest -DfailIfNoTests=false test