Browse Source

Closes connection on retry.

see gh-1866
pull/1971/head
spencergibb 4 years ago
parent
commit
5e0baf5480
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 14
      spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java
  2. 4
      spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java

14
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; @@ -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 @@ -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 @@ -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);
}

4
spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java

@ -117,6 +117,8 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest @@ -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 @@ -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;
}

Loading…
Cancel
Save