Spring web flux WebClient : Connection rest by peers,#block terminated with an error.Error has been observed at the following site

Viewed 12732

i am using spring web flux, web client to call a rest api. i am getting the following error.

Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8  Suppressed: java.lang.Exception: #block terminated with an error 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8      at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99) ~[reactor-core-3.3.2.RELEASE.jar!/:3.3.2.RELEASE] 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8      ... 97 common frames omitted 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 Caused by: io.netty.channel.unix.Errors$NativeIoException: readAddress(..) failed: Connection reset by peer 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8  Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:  
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 Error has been observed at the following site(s): 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8  |_ checkpoint ? Request to GET https://cc-qa.app/api/matches/list/?status=current&page=0&size=100 [DefaultWebClient] 

is the problem with my web client call or the api i am calling ? i am confused as it showing many error like Connection rest by peers,#block terminated with an error.Error has been observed at the following site. how to solve this ? please find the code below

  @Bean
  public WebClient restClient() {

    String baseurl = env.getProperty("base-url");
    int memoryLimit = Integer.parseInt(env.getProperty("webclient-buffer-size"));

    ExchangeStrategies exchangeStrategies =
        ExchangeStrategies.builder()
            .codecs(
                configurer -> configurer.defaultCodecs().maxInMemorySize(1024 * 1024 * memoryLimit))
            .build();
    return WebClient.builder()
        .exchangeStrategies(exchangeStrategies)
        .baseUrl(baseurl)
        .build();
  }

this the api call:

webClient
              .get()
              .uri("/api/matches/list/?status=current&page=0&size=100")
              .header("authorization", accessToken)
              .retrieve()
              .bodyToMono(InfoPayload.class)
              .block();

please help me to find the issue . thanks in advance

2 Answers

the problem solved after adding the client Connector.

 private ClientHttpConnector connector() {
    return new 
 ReactorClientHttpConnector(HttpClient.create(ConnectionProvider.newConnection()));
  }

WebClient.builder()
        .clientConnector(connector())
        .exchangeStrategies(exchangeStrategies)
        .baseUrl(baseurl)
        .build();

For me adding the baseUrl solved the issue. Just .mutate() the existing instance of WebClient/WebTestClient and set the .baseUrl(<>)

Related