Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-17473

The onstatus method of webclient causes a memory leak.

    XMLWordPrintable

    Details

    • Last commented by a User:
      true

      Description

       

      private WebClient webClient;
      
          private final static int DEFAULT_CONNECT_TIMEOUT = 900;
          private final static int DEFAULT_SOCKET_TIMEOUT = 900;
      
          @PostConstruct
          public void initialize() {
              ReactorClientHttpConnector connector = new ReactorClientHttpConnector(options ->
                      options.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, DEFAULT_CONNECT_TIMEOUT)
                              .poolResources(PoolResources.fixed("httpPool", 1000))
                              .afterNettyContextInit(ctx -> {
                                  ctx.addHandlerLast(new ReadTimeoutHandler(DEFAULT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS));
                              }));
      
              webClient = WebClient.builder()
                      .clientConnector(connector)
                      .build();
      
          }
      
      @GetMapping("/test")
          public Mono<String> webclientTest() {
      
              return webClient
                      .get()
                      .uri("http://testurl.com/response500test")
                      .retrieve()
                      .onStatus(httpStatus -> httpStatus != HttpStatus.OK, clientResponse -> Mono.error(new RuntimeException(String.format("api status: %s", clientResponse.statusCode()))))
                      .bodyToMono(String.class);
          }
      

      The above source code called an API that responded to 500 errors with 600 tps.

       

      io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 16777216 byte(s) of direct memory (used: 8573157383, max: 8589934592)
      

      The onstatus method of webclient causes a memory leak.

       

       

      In the photo attached above
      We used the onStatus method from 13:40 to 13:48,
      We removed the onStatus method from 13:55 to 14:00.
      Is this a bug?
      Why does the onStatus method cause a memory leak?

      I used SpringBoot version 2.0.4 and upgraded to 2.1.0, but I still have a problem.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              kimseongil KimSeongIl
              Last updater:
              Spring Issuemaster
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 28 weeks, 6 days ago