MVC Spring Retry based retry filter never retries on exceptions

Đang mở
#4,340 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, spring, spring-boot
Lĩnh vực
api, backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Java
Star
4.9k
Fork
3.5k
Merge trung bình
1 ngày 13 giờ
Pull request đã merge (30 ngày)
14

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của spring-cloud/spring-cloud-gateway

Tất cả issue của spring-cloud/spring-cloud-gateway

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.