Repository navigation
fix(server): release connection pools of instances that are gone - #5949
Merged
Merged
Conversation
The instance WebClient used Reactor Netty's global connection provider, which keeps one pool per remote address and never removes it. Every instance address that disappears (pods after a restart or scale-out) left its pool and its idle sockets behind. Use a dedicated connection provider that closes idle connections and disposes pools that have been inactive for a minute, configurable with spring.boot.admin.monitor.connection-pool.*. It is built with the application's ClientHttpConnectorBuilder and HttpClientSettings, so SSL, timeouts, redirects and the SSRF InetAddressFilter still apply. The connection limit per instance stays at 500, as in the global pool, and a ClientHttpConnector bean defined by the application is left in place.
Contributor
Author
|
Thanks for merging this PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spring Boot Admin leaks a connection pool for every instance address it has ever talked to. The instance WebClient uses Reactor Netty's global connection provider, which keeps one pool per remote address and never drops it. Where addresses change all the time (Kubernetes pods after a restart or a scale-out), the pools and their idle sockets pile up until the server runs out of file descriptors or heap.
With this change the instance WebClient gets its own
ConnectionProvider, which closes idle connections and disposes pools that nobody has used for a while. The timings can be tuned underspring.boot.admin.monitor.connection-pool:max-idle-time(15s),eviction-interval(30s) andinactive-pool-timeout(1m).I tried to keep everything else as it was:
ClientHttpConnectorBuilderandHttpClientSettings, so SSL bundles, timeouts, redirects and the SSRFInetAddressFilterkeep working.SsrfConnectionFilterTestpasses unchanged.ClientHttpConnectorbean, that one is used and not replaced. Non-Reactor connectors are not touched either.InstanceWebClientCustomizers still run last.shouldNotUseGlobalConnectionPoolForInstanceRequestsfails onmasterand passes with the change. The other new tests cover the properties and the points above.Measurements
To see the effect I registered, health-checked and deregistered 10,000 instances against the reactive sample in Docker (512 MB heap), waited 150 s and forced a full GC:
masterThe 34 MB that remain are instance snapshots and the event log, which is a separate topic.