Skip to content

[type:fix] retry network failures with exponential backoff - #7201

Merged
Aias00 merged 4 commits into
apache:masterfrom
dengliming:fix-6636-exponential-retry-errors
Oct 17, 2026
Merged

Aias00 merged 4 commits into
apache:masterfrom
dengliming:fix-6636-exponential-retry-errors

Conversation

@dengliming

Copy link
Copy Markdown
Member

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

Aias00
Aias00 previously approved these changes Sep 24, 2026

@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.

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 + 1 invocations (1 initial + 3 retries), so transientErrors(true) is not turning this into an infinite retry loop.
  • onRetryExhaustedThrow still converts exhaustion into IllegalStateException("Retry limit exceeded"), so callers see the same terminal error type as before.
  • Switching the test to StepVerifier.withVirtualTime keeps 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 sunnysabor 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.

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 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.

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.

@Aias00

Aias00 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Hi @dengliming, this PR currently has merge conflicts with the master base branch, so CI cannot validate it against the latest code. Please rebase/merge the latest master and resolve the conflicts, then push the updated branch. Once the conflicts are cleared, CI will re-run automatically and we can continue the review. Thanks!

@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.

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 now HttpMethod.GET.equals(method) && isTransientFailure(throwable); isTransientFailure walks the cause chain for TimeoutException, ConnectTimeoutException, ReadTimeoutException, ConnectException, SocketTimeoutException, and PrematureCloseException.
  • onRetryExhaustedThrow now rethrows retrySignal.failure() instead of wrapping in IllegalStateException("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 asserts retryTimes + 1 attempts.

Verification

CI: pr_build, Analyze (java), check-license-header, rat_check, scope, sql-matrix all pass.

Conclusion

APPROVE.

@Aias00
Aias00 merged commit 864c44d into apache:master Oct 17, 2026
28 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] ExponentialRetryBackoffStrategy retries only on IllegalStateException, never on real network errors

3 participants