diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java index c468bc51..788b2f84 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java @@ -67,6 +67,12 @@ public class RetryGatewayFilterFactory implements GatewayFilterFactory { retry.validate(); Predicate> predicate = context -> { + boolean retryableAttempt = context.iteration() < retry.getRetries(); + + if (!retryableAttempt) { + return false; + } + ServerWebExchange exchange = context.applicationContext(); HttpStatus statusCode = exchange.getResponse().getStatusCode(); HttpMethod httpMethod = exchange.getRequest().getMethod(); @@ -84,7 +90,7 @@ public class RetryGatewayFilterFactory implements GatewayFilterFactory { }; //TODO: use Repeat statics once updated with a create() like method - Repeat repeat = DefaultRepeat.create(predicate, retry.getRetries()); + Repeat repeat = Repeat.onlyIf(predicate); //TODO: support timeout, backoff, jitter, etc... in Builder return apply(repeat);