dragon-zhang edited a comment on issue #2627:
URL:
https://github.com/apache/incubator-shenyu/issues/2627#issuecomment-1051534499
> when upstream is fail, it can be remove? now, not be remove in upstream
List?
It's been removed in upstreamList and no `bug` in `UpstreamCacheManager`.
The problem occurred in `WebClientPlugin`:
```java
@Override
public Mono<Void> execute(final ServerWebExchange exchange, final
ShenyuPluginChain chain) {
final ShenyuContext shenyuContext =
exchange.getAttribute(Constants.CONTEXT);
assert shenyuContext != null;
URI uri = exchange.getAttribute(Constants.HTTP_URI);
if (Objects.isNull(uri)) {
Object error = ShenyuResultWrap.error(exchange,
ShenyuResultEnum.CANNOT_FIND_URL, null);
return WebFluxResultUtils.result(exchange, error);
}
long timeout = (long)
Optional.ofNullable(exchange.getAttribute(Constants.HTTP_TIME_OUT)).orElse(3000L);
int retryTimes = (int)
Optional.ofNullable(exchange.getAttribute(Constants.HTTP_RETRY)).orElse(0);
LOG.info("The request urlPath is {}, retryTimes is {}",
uri.toASCIIString(), retryTimes);
HttpMethod method =
HttpMethod.valueOf(exchange.getRequest().getMethodValue());
WebClient.RequestBodySpec requestBodySpec =
webClient.method(method).uri(uri);
return handleRequestBody(requestBodySpec, exchange, timeout,
retryTimes, chain);
}
private Mono<Void> handleRequestBody(final WebClient.RequestBodySpec
requestBodySpec,
final ServerWebExchange exchange,
final long timeout,
final int retryTimes,
final ShenyuPluginChain chain) {
return requestBodySpec.headers(httpHeaders -> {
httpHeaders.addAll(exchange.getRequest().getHeaders());
// remove gzip
List<String> acceptEncoding =
httpHeaders.get(HttpHeaders.ACCEPT_ENCODING);
if (CollectionUtils.isNotEmpty(acceptEncoding)) {
acceptEncoding = Stream.of(String.join(",",
acceptEncoding).split(",")).collect(Collectors.toList());
acceptEncoding.remove(Constants.HTTP_ACCEPT_ENCODING_GZIP);
httpHeaders.set(HttpHeaders.ACCEPT_ENCODING,
String.join(",", acceptEncoding));
}
httpHeaders.remove(HttpHeaders.HOST);
})
.body(BodyInserters.fromDataBuffers(exchange.getRequest().getBody()))
.exchange()
.doOnError(e -> LOG.error(e.getMessage(), e))
.timeout(Duration.ofMillis(timeout))
//here, retry means just retry to one uri when fail
.retryWhen(Retry.anyOf(TimeoutException.class,
ConnectTimeoutException.class, ReadTimeoutException.class)
.retryMax(retryTimes)
.backoff(Backoff.exponential(Duration.ofMillis(200),
Duration.ofSeconds(20), 2, true)))
.flatMap(e -> doNext(e, exchange, chain));
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]