0

I started working on spring-webflux, and unfortunately, my application stuck for an indefinite time.

I have two applications one is reactive and another one is non-reactive.

Application A (NonReactive) makes requests to Application B (Reactive) using WebClient.

Client-Side -

 RequestDTO request = new RequestDTO();
 Mono<ResponseDTO> monoResponse = webClient.post()
                .uri("uri")
                .contentType(MediaType.APPLICATION_JSON)
                .body(BodyInserters.fromObject(request ))
                .retrieve()
                .bodyToMono(ResponseDTO.class)
                .timeout(Duration.ofMillis(timeout))
                .retryWhen(Retry.any()
                        .exponentialBackoffWithJitter(Duration.ofMillis(20), Duration.ofMillis(300))
                        .retryMax(numOfRetries)
                        .doOnRetry(s -> LOGGER.info("Retrying due to " + s)))
                .onErrorResume(e -> Mono.error(new RuntimeException(e)))
                .switchIfEmpty(Mono.error(new RuntimeException("Invalid response: " + request)));

 monoResponse.subscribe(response -> {
                    String responseText = null;
                    try {
                        responseText  = objectMapper.writeValueAsString(response);
                    } catch (JsonProcessingException e) {
                        log.error("Error while parsing", e);
                    }                   
                }, e -> {
                   log.error("Exception",e);
                });

Server Side -

    @PostMapping(value = "/process")
    public Mono<ResponseEntity<ResponseDTO>> process(@RequestBody RequestDTO request,
            ServerHttpRequest serverHttpRequest) {
        return Mono.just(ResponseEntity.ok(reactiveService.process(request)));
    }

Dependencies

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.9.RELEASE</version>
    </parent>


    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceencoding>UTF-8</project.build.sourceencoding>
        <project.reporting.outputencoding>UTF-8</project.reporting.outputencoding>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>io.projectreactor.addons</groupId>
            <artifactId>reactor-extra</artifactId>
            <version>3.3.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
    </dependencies>

I tried looking into the CPU usages, thread dump I was unable to see anything and cpu usage was only 7%.

Could someone please suggest what area should I look for.

Atul
  • 133
  • 3
  • 12
  • All requests are stuck? What happens if you remove retry? – Martin Tarjányi Dec 10 '20 at 22:14
  • what is `reactiveService`? – Toerktumlare Dec 10 '20 at 23:12
  • I have created service to process request – Atul Dec 11 '20 at 04:42
  • Client retries 3 times and then gives a timeout, as the server is not responsive. – Atul Dec 11 '20 at 04:44
  • ```Retrying due to iteration=1 exception=reactor.netty.internal.shaded.reactor.pool.PoolAcquireTimeoutException: Pool#acquire(Duration) has been pending for more than the configured timeout of 45000ms backoff={14ms/300ms}``` – Atul Dec 11 '20 at 05:04
  • Retrying due to iteration=2 exception=reactor.netty.internal.shaded.reactor.pool.PoolAcquireTimeoutException: Pool#acquire(Duration) has been pending for more than the configured timeout of 45000ms backoff={19ms/300ms} – Atul Dec 11 '20 at 05:27
  • @Atul Hope you are using the correcr uri ('uri' is in webclient post request in client side). Anyway how did you conclude the server is not responsive? Did you try a simple postman call? Or did you try restTemplate in your non-reactive client side instead of webclient? – Nipuna Saranga Dec 11 '20 at 11:36
  • @NipunaSaranga - I tried a couple of requests using curl and postman .. both requests didn't reach server – Atul Dec 11 '20 at 20:16
  • @Atul: how did you conclude that requests didnt reach? – pradosh nair Dec 12 '20 at 01:24
  • @Atul then forget about client for the moment and try to get server up. The error 'exception=reactor.netty.internal.shaded.reactor.pool.PoolAcquireTimeoutException' is client side error, right? Check error logs in server side. Get it working and responsive for curls and postman calls. – Nipuna Saranga Dec 12 '20 at 02:24
  • Service A communicates with Service Service B using webclient -> that connectin is working fine. Service B sends the request to 3rd Party Endpoint. Service B has PoolAcquireTimeoutException and it has stopped accepting a connection. The moment Service B started it started working fine. – Atul Dec 13 '20 at 16:11

0 Answers0