得到很多`PrematureCloseException:连接在响应之前过早关闭`

Getting a lot of `PrematureCloseException : Connection prematurely closed BEFORE response`

我们收到了很多:

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