MVC Spring Retry based retry filter never retries on exceptions

オープン
#4,340 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java, spring, spring-boot
領域
api, backend

調査の方向性

Start with GatewayRetryFilterFunctions.java in spring-cloud-gateway-server-webmvc and trace how SimpleRetryPolicy and HttpRetryPolicy combine; the issue links the relevant lines. Compare the Spring Framework based MVC and WebFlux filters, then add tests showing configured exception retries and status based retries stop at the configured limit. The issue author says a fix with tests is ready and plans to open a PR, so check for that work before starting.

索引モデルが issue の本文から書いたものです。

説明

waiting-for-triage

Describe the bug
Spring Cloud Gateway Server WebMVC 5.0.x (also on main), using the Spring Retry based filter (GatewayRetryFilterFunctions, the default when Spring Retry is on the classpath).

Exception based retries never happen. GatewayRetryFilterFunctions.retry(RetryConfig) combines a SimpleRetryPolicy (built from the configured exceptions) with HttpRetryPolicy in a CompositeRetryPolicy:

https://github.com/spring-cloud/spring-cloud-gateway/blob/b57ce6613e/spring-cloud-gateway-server-webmvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/GatewayRetryFilterFunctions.java#L75-L77

The composite is pessimistic (every policy must agree), and HttpRetryPolicy extends NeverRetryPolicy: for anything other than a RetryException it returns super.canRetry(context), which is false once registerThrowable has been called. So the configured exceptions are effectively ignored and the first exception is rethrown without any retry. The Framework based MVC filter and the WebFlux filter do retry on exceptions.

Related to #3862, which reports the same symptom (no retry when the proxied call fails with an exception) for the MVC gateway.

Sample
Reproduced with Spring Boot 4.0.9 / Spring Cloud 2025.1.4 and spring-retry on the classpath: a route with retry(c -> c.setRetries(3).addExceptions(ResourceAccessException.class)) in front of a backend that closes the connection without a response. The filter raised ResourceAccessException after a single attempt (Retry: count=0 → Retry failed last attempt: count=1). Expected: the configured number of retries.

Proposed fix: HttpRetryPolicy.canRetry should only decide for RetryException (status based retries) and return true otherwise, leaving classification to the SimpleRetryPolicy, which already knows the configured exceptions. Making the composite optimistic instead would not work, since HttpRetryPolicy has no attempt counter and status based retries would never stop. I have a fix with tests ready and will open a PR.

主要言語
Java
スター
4.9k
フォーク
3.5k
平均マージ
1日 13時間
マージ済み PR(30日)
14

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

spring-cloud/spring-cloud-gateway のほかの issue

spring-cloud/spring-cloud-gateway の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。