Kami menerima banyak:

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)

Klien dibangun seperti ini:

        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();

Dan filternya adalah:

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

Kesalahan hanya terjadi kadang-kadang. Kami memiliki banyak layanan, jadi sulit untuk mengetahui alasannya.

Ada ide?

1
igr 10 Juli 2020, 19:35

1 menjawab

Jawaban Terbaik

Kami tidak dapat menyimpulkan banyak dalam kasus saya. https://github.com/reactor/reactor-netty/issues/1217

0
igr 22 Juli 2020, 21:15