diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java index 924a733e..d3e998e4 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java @@ -28,6 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; +import reactor.netty.Connection; import reactor.retry.Backoff; import reactor.retry.Repeat; import reactor.retry.RepeatContext; @@ -83,9 +84,8 @@ public class RetryGatewayFilterFactory boolean retryableStatusCode = retryConfig.getStatuses() .contains(statusCode); - if (!retryableStatusCode && statusCode != null) { // null status code - // might mean a - // network exception? + // null status code might mean a network exception? + if (!retryableStatusCode && statusCode != null) { // try the series retryableStatusCode = retryConfig.getSeries().stream() .anyMatch(series -> statusCode.series().equals(series)); @@ -213,6 +213,14 @@ public class RetryGatewayFilterFactory * Use {@link ServerWebExchangeUtils#reset(ServerWebExchange)} */ public void reset(ServerWebExchange exchange) { + Connection conn = exchange + .getAttribute(ServerWebExchangeUtils.CLIENT_RESPONSE_CONN_ATTR); + if (conn != null) { + trace("disposing response connection before next iteration"); + conn.dispose(); + exchange.getAttributes() + .remove(ServerWebExchangeUtils.CLIENT_RESPONSE_CONN_ATTR); + } ServerWebExchangeUtils.reset(exchange); } diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java index b2e2a869..69a51265 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java @@ -117,6 +117,8 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest .header(HttpHeaders.HOST, "www.retrypostconfig.org") .bodyValue("HelloConfig").exchange().expectStatus().isOk() .expectBody(String.class).isEqualTo("3"); + assertThat(this.capture.toString()) + .contains("disposing response connection before next iteration"); } @Test @@ -254,7 +256,7 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest AtomicInteger num = getCount(key); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .header("X-Retry-Count", String.valueOf(num)) - .body("bodys did not match on try" + num); + .body("body did not match on try" + num); } return response; }