-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReactorClientHttpConnector creates new HttpClient for every request #33093
Comments
Further insight: It looks like this happens to all Lines 109 to 115 in 06b492d
For those instances, the |
Where does the |
@jhoeller I'm doing this: @Bean
WebClient apiV1WebClient(WebClient.Builder builder, WebClientSsl ssl) {
return builder
.apply(ssl.fromBundle("client-auth"))
.build();
} The |
Alright, thanks for the deep dive! I'll fix this for 6.1.11 as suggested above then since it matches the scenario I had in mind there. |
In 6.1.9, since commit 7785f94 (related issue: #32945),
this.httpClient
is no longer assigned. The assignment should probably have happened here:spring-framework/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java
Lines 128 to 131 in 5356a1b
As a consequence, a new
HttpClient
instance is created for every request. Apart from the possible performance impact, this is causing a memory leak in my application: I'm using client certificate authentication configured through Boot'sSslBundle
support. This causes the creation of newSslContext
instances alongside each newHttpClient
inorg.springframework.boot.autoconfigure.web.reactive.function.client.ReactorClientHttpConnectorFactory
.Then, because Netty's
SslContext
implementations don't implementhashCode()
, Reactor Netty's connection pooling doesn't work properly, causing new HTTP connection pools to be created for every request (config.channelHash()
returns distinct values for every request https://github.com/reactor/reactor-netty/blob/v1.1.20/reactor-netty-core/src/main/java/reactor/netty/resources/PooledConnectionProvider.java#L127-L133).All these connection pools are then never disposed of (this is Reactor Netty's default configuration I believe), eventually causing an OOME.
TL;DR
SslContext
in the pool key, becauseSslContext
has been configured by Spring Boot'sSslBundle
feature for every request, becauseHttpClient
instances for every request.The leak itself may be fixed in Netty (should
SslContext
implementations have stable hash codes?), but it was surfaced by the commit in Spring Framework.The text was updated successfully, but these errors were encountered: