-
Notifications
You must be signed in to change notification settings - Fork 654
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
HTTP Connection Pooling May Not Work Properly with Explicitly Configured Client SSL #3315
Comments
@kzander91 From the sample that you provided, it seems that you recreate the client and the ssl context every time. I would say that this is not a very good pattern and easily can lead to memory problems (see #1054). By design if you do not share the |
@violetagg Yes, the memory problems is exactly why I noticed this issue. Recreating the ssl context every time is not intended and a bug in Spring, see spring-projects/spring-framework#33093. Thanks for the feedback, so not sharing pools across different However, could it make sense to limit the number of pools (configurable of course) and maybe log warnings if additional pools are being created? Something like this would have saved me a lot of time when debugging this issue. |
@kzander91 Would you like to provide a PR? |
You can also configure the pool to be disposed if not used for a specific time - |
No, I don't feel comfortable enough with the code base to attempt an implementation of that myself.
Thank you for the hint, I'll keep that in mind as a possible workaround. |
Let me close this one. I opened a new issue for limiting the number of the connection pools #3318 |
Expected Behavior
Identically configured
HttpClient
instances should share HTTP connection pool instances.Actual Behavior
A new pool is created for every connection acquiry, because Netty's
SslContext
does not produce stable hash codes. This causesHttpClientConfig#channelHash
to be unstable as well, in turn causingPooledConnectionProvider#acquire
to always create a new pool instance for every request.In my application this eventually leads to OOME crashes because the pools don't seem to be disposed within a reasonable amount of time.
Steps to Reproduce
HttpClient
andSslContext
instances.Creating a new [http] client pool [PoolFactory{evictionInterval=PT0S, leasingStrategy=fifo, maxConnections=500, maxIdleTime=-1, maxLifeTime=-1, metricsEnabled=false, pendingAcquireMaxCount=1000, pendingAcquireTimeout=45000}] for [httpbin.org/<unresolved>:443]
.Reproducer (unzip and run
mvnw spring-boot:run
): repro.zipCode:
The issue doesn't arise if I create and reuse a single
SslContext
instance by instantiating it outside thedefer()
.This reproducer is a bit of a contrived example, please see spring-projects/spring-framework#33093 for how I noticed this behaviour in my real-world application.
Possible Solution
This would most likely be fixed if Netty's
SslContext
implementedhashCode()
, but I was unsure if this is actually a "bug" on Netty's side...Additionally, implementing a proper
hashCode()
method may not be that simple or even possible, because it wraps ajavax.net.ssl.SSLContext
which doesn't implement that either.Thus, one could argue that there isn't anything to "fix" on Netty's side, in turn suggesting a bug on Reactor's side in including the
SslContext
in thechannelHash()
.Your Environment
java -version
):The text was updated successfully, but these errors were encountered: