Closes connection on retry.

see gh-1866
This commit is contained in:
spencergibb
2020-09-25 15:26:22 -04:00
parent 0056beff25
commit 5e0baf5480
2 changed files with 14 additions and 4 deletions

View File

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

View File

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