Closed
Description
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:
- 스크린샷 2018-11-07 오후 2.01.06.png (36.31 kB)
Issue Links:
- WebClient logs "Only one connection receive subscriber allowed" when response status is an error [SPR-17564] #22096 WebClient logs "Only one connection receive subscriber allowed" when response status is an error
Referenced from: commits f73a522, c187cb2
Backported to: 5.0.11