Closes connection on retry.
see gh-1866
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user