5

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 2

3

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();
3
  • 1
    What does the client connector do? Nov 17, 2021 at 18:01
  • ClientConnector offers a low-level API that can be used to connect SocketChannels to listening servers.
    – saij9999
    Nov 18, 2021 at 4:07
  • if you face block terminated error. you should create a new connection while making a api call. this would solve the issue. the above code is for WebClient. it may be slightly differs for rest template and others.
    – saij9999
    Nov 18, 2021 at 4:09
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.