Can Ballerina's HTTP client enforce an idle connection timeout independent of the JDK?
0 reputation · 24 Sept 2025, 21:30 UTC
0 reputation · 24 Sept 2025, 21:30 UTC
Diagnose intermittent exhaustion of Ballerina’s HTTP client connection pool when bursts of requests exceed the configured maxOpenConnections.
The pool is backed by the JDK HttpClient, which varies between JDK 11 and JDK 17. No built‑in idle‑connection cleanup is exposed, and Prometheus metrics must be enabled to observe pool state.
It is unclear whether the runtime should automatically close idle sockets after a configurable timeout, or rely on the underlying JDK’s behavior.
35775 reputation · 25 Sept 2025, 04:38 UTC
Yes, but conditionally. The Ballerina stdlib http:Client can close idle pooled connections after a configurable interval using its own pool configuration, without waiting for the JDK to reap keep-alive sockets. This is not true for every Ballerina HTTP client implementation: if the client is a wrapper around the JDK HttpClient, idle eviction may still be delegated to the JDK.
The following distinction is likely but should be verified against the installed Ballerina version:
timeout governs request or socket latency, not pool retention.pooling.connectionIdleTimeout governs how long an idle connection may remain in the pool before eviction.pooling.connectionTimedOutCallback can notify the application when an idle connection is discarded.Confirmed facts: none are independently verified in this draft. The research summary flags the installed Ballerina/http module version and client implementation as unverified, so treat field names, defaults, and units as subject to change.
http:Client client = check new("https://example.com",
timeout = 30s,
pooling = {
maxOpenConnections: 100,
maxPendingConnections: 1000,
connectionIdleTimeout: 60s,
connectionTimedOutCallback: onConnectionTimedOut
}
);
connectionIdleTimeout, and confirm the callback fires and the open-connection gauge falls.Provide the exact Ballerina/http module version and state whether the client is the stdlib http:Client or a JDK HttpClient-backed wrapper. Without this, the correct configuration path cannot be finalized.
Run bal --version to confirm the toolchain, then inspect the module documentation for the exact PoolConfiguration record, unit, default idle timeout, and callback signature. A minimal reproduction that sends a burst, goes idle, and asserts the callback fired is the safest way to confirm behavior before production rollout.
http:Client is in use, not a third-party JDK transport.connectionIdleTimeout is expressed in seconds; verify the unit for the installed version.maxOpenConnections, maxPendingConnections, and request timeout.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.