Skip to content

Expose disposeInactivePoolsInBackground for HttpClient connection pool#4191

Open
seonwooj0810 wants to merge 1 commit into
spring-cloud:mainfrom
seonwooj0810:fix/issue-4165-dispose-inactive-pools
Open

Expose disposeInactivePoolsInBackground for HttpClient connection pool#4191
seonwooj0810 wants to merge 1 commit into
spring-cloud:mainfrom
seonwooj0810:fix/issue-4165-dispose-inactive-pools

Conversation

@seonwooj0810
Copy link
Copy Markdown

Fixes #4165

Problem

HttpClientProperties.Pool exposes several Reactor Netty connection-pool knobs (max-idle-time, max-life-time, eviction-interval, …) but not ConnectionProvider.Builder#disposeInactivePoolsInBackground(disposeInterval, poolInactivity).

The existing eviction-interval (evictInBackground) only evicts idle connections within a pool; it does not remove the pool entries themselves from Reactor Netty's internal channelPools map. When downstream instances churn — e.g. Kubernetes pods rolling, so the remote IP:port (and therefore the PoolKey) keeps changing — entries accumulate and are never reclaimed, which manifests as a slow memory leak (see #4165 for the analysis and a linked Reactor Netty report).

Change

Expose the missing knob, mirroring how the other pool properties are wired:

  • Add inactive-pool-dispose-interval and pool-inactivity (both Duration, null/disabled by default) to HttpClientProperties.Pool.
  • In HttpClientFactory#buildConnectionProvider, call builder.disposeInactivePoolsInBackground(...) only when both are set, so default behavior is unchanged.
spring.cloud.gateway.server.webflux.httpclient.pool.inactive-pool-dispose-interval=5m
spring.cloud.gateway.server.webflux.httpclient.pool.pool-inactivity=5m

Test evidence

Extended the existing GatewayAutoConfigurationTests#nettyHttpClientConfigured binding test to set and assert both new properties.

./mvnw -pl spring-cloud-gateway-server-webflux -Dtest='GatewayAutoConfigurationTests#nettyHttpClientConfigured' test
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

checkstyle + spring-javaformat validate pass. Commit is DCO signed-off.

Verification done

  1. No in-flight PR (searched open/closed PRs for disposeInactive / 4165 — none). 2. No self-claim comments on the issue. 3. Code-focused — touches only .java. 4. Confirmed the property/builder call is absent on current main. 6. Triage gate N/A (spring-cloud/, not spring-projects/).

Add configuration properties to expose Reactor Netty's
ConnectionProvider.Builder#disposeInactivePoolsInBackground(disposeInterval,
poolInactivity). Unlike the existing eviction-interval (which evicts idle
connections), this disposes connection pools that have been entirely inactive,
preventing unbounded growth of the channelPools map when downstream instances
churn (e.g. Kubernetes pods rolling, so the remote address changes).

Both spring.cloud.gateway.server.webflux.httpclient.pool.inactive-pool-dispose-interval
and ...pool.pool-inactivity must be set for the background disposal to be enabled;
otherwise behavior is unchanged.

Fixes spring-cloudgh-4165

Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose disposeInactivePoolsInBackground configuration for HttpClient ConnectionProvider

2 participants