Skip to content

fix: expose idleTimeout, timeToLive and validateAfterInactivity on HttpClient5 connection pool - #1293

Draft
cassiofariasmachado wants to merge 1 commit into
mainfrom
fix/idle-timeout
Draft

cassiofariasmachado wants to merge 1 commit into
mainfrom
fix/idle-timeout

Conversation

@cassiofariasmachado

Copy link
Copy Markdown
Member

Context

On BTP Cloud Foundry, NAT gateways silently drop idle TCP connections after a hyperscaler-specific timeout (GCP ~600s, Azure ~240s, AWS ~300s). Without connection pool eviction configured, the SDK keeps half-open sockets indefinitely. The next request that reuses one stalls for ~120s waiting for the OS TCP retry budget before the retry strategy reconnects.

This PR exposes three new opt-in configuration methods on ApacheHttpClient5FactoryBuilder so affected applications can configure connection pool eviction without changing behavior for other consumers:

  • idleTimeout(Duration) — evict connections idle longer than this period
  • timeToLive(Duration) — hard cap on total connection lifetime regardless of activity
  • validateAfterInactivity(Duration) — probe connections after inactivity before reuse

All three default to null (no change in existing behavior). DefaultApacheHttpClient5Factory applies each only when explicitly set via a new buildConnectionConfig() helper.

Workaround for affected applications (usable today before a release):

ApacheHttpClient5Accessor.setHttpClientFactory(
    ApacheHttpClient5FactoryBuilder.create()
        .idleTimeout(Duration.ofSeconds(55))
        .timeToLive(Duration.ofMinutes(10))
        .validateAfterInactivity(Duration.ofSeconds(2))
        .build());

Feature scope:

  • idleTimeout(Duration) added to ApacheHttpClient5FactoryBuilder
  • timeToLive(Duration) added to ApacheHttpClient5FactoryBuilder
  • validateAfterInactivity(Duration) added to ApacheHttpClient5FactoryBuilder
  • DefaultApacheHttpClient5Factory applies each setting only when explicitly provided
  • HC4 AbstractHttpClientFactory — follow-up PR (HC4 requires a background evictor thread)

Definition of Done

  • Functionality scope stated & covered
  • Tests cover the scope above
  • Error handling created / updated & covered by the tests above
  • Documentation updated
  • Release notes updated

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