Skip to content

fix(server): release connection pools of instances that are gone - #5949

Merged
SteKoe merged 1 commit into
codecentric:masterfrom
ngriaznov:dev/gifted-wozniak-8hknn6
Nov 27, 2026
Merged

SteKoe merged 1 commit into
codecentric:masterfrom
ngriaznov:dev/gifted-wozniak-8hknn6

Conversation

@ngriaznov

Copy link
Copy Markdown
Contributor

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 under spring.boot.admin.monitor.connection-pool: max-idle-time (15s), eviction-interval (30s) and inactive-pool-timeout (1m).

I tried to keep everything else as it was:

  • The connector is still built from the application's ClientHttpConnectorBuilder and HttpClientSettings, so SSL bundles, timeouts, redirects and the SSRF InetAddressFilter keep working. SsrfConnectionFilterTest passes unchanged.
  • The limit stays at 500 connections per instance, the same as in the global pool.
  • If the application defines its own ClientHttpConnector bean, that one is used and not replaced. Non-Reactor connectors are not touched either.
  • InstanceWebClientCustomizers still run last.

shouldNotUseGlobalConnectionPoolForInstanceRequests fails on master and 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:

master this PR
Live heap growth 220.3 MB 34.0 MB
Open file descriptors 910 → 20,573 42 → 42
Pools / sockets left 10,001 / 19,663 0 / 0

The 34 MB that remain are instance snapshots and the event log, which is a separate topic.

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.
@ngriaznov
ngriaznov requested a review from a team as a code owner November 21, 2026 13:06
@SteKoe
SteKoe enabled auto-merge (squash) November 27, 2026 14:43
@SteKoe
SteKoe merged commit 75afa10 into codecentric:master Nov 27, 2026
2 checks passed
@ngriaznov

Copy link
Copy Markdown
Contributor Author

Thanks for merging this PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants