Skip to content

The onstatus method of webclient causes a memory leak. [SPR-17473] #22005

Closed
@spring-projects-issues

Description

@spring-projects-issues

KimSeongIl opened SPR-17473 and commented

 

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.

 

!스크린샷 2018-11-07 오후 2.01.06.png!

 

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.


Affects: 5.0.8, 5.1.2

Attachments:

Issue Links:

Referenced from: commits f73a522, c187cb2

Backported to: 5.0.11

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions