gpt4 book ai didi

java - 获取大量 `PrematureCloseException : Connection prematurely closed BEFORE response`

转载 作者:行者123 更新时间:2023-12-05 07:04:56 45 4
gpt4 key购买 nike

我们收到了很多:

reactor.core.ReactiveException: reactor.netty.http.client.PrematureCloseException: Connection prematurely closed BEFORE response
at reactor.core.Exceptions.propagate(Exceptions.java:393)
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:97)
at reactor.core.publisher.Mono.block(Mono.java:1678)

客户端是这样构建的:

        httpClient = HttpClient.newConnection().compress(true);
return WebClient.builder()
.exchangeStrategies(ExchangeStrategies.builder().codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(-1)).build())
.baseUrl(url)
.filter(errorHandlingFilter(platformService))
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.clientConnector(new ReactorClientHttpConnector(httpClient))
.build();

过滤器是:

    private ExchangeFilterFunction errorHandlingFilter(final PlatformService service) {
return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
if (!isErrorStatusCode(clientResponse)) {
return Mono.just(clientResponse);
}

final Optional<org.springframework.http.MediaType> mediaType = clientResponse.headers().contentType();
boolean jsonResponse = true;

if (mediaType.isPresent()) {
final org.springframework.http.MediaType mt = mediaType.get();

if (!mt.getType().equals("application") && !mt.getSubtype().equals("json")) {
jsonResponse = false;
}
}

if (!clientResponse.statusCode().is5xxServerError()) {
return clientResponse
.bodyToMono(String.class)
.flatMap(s -> Mono.error(new UpstreamException(s, service)));
}

if (!jsonResponse) {
return clientResponse
.bodyToMono(String.class)
.flatMap(e -> Mono.error(new UpstreamException(e, service)));
}

return clientResponse
.bodyToMono(RuntimeException.class)
.flatMap(e -> Mono.error(new UpstreamException(e, service)));
});
}

错误只是偶尔发生。我们有很多服务,所以很难找出原因。

有什么想法吗?

最佳答案

在我的案例中,我们无法得出太多结论。 https://github.com/reactor/reactor-netty/issues/1217

关于java - 获取大量 `PrematureCloseException : Connection prematurely closed BEFORE response`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62838689/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com