Time Out an Apache HttpClient 5 Proxy That Stalls During CONNECT
Set the connection manager's socket I/O timeout for tunnel setup, alongside the separate TCP connect timeout.
The proxy accepted TCP but never finished its CONNECT reply. The website response has not begun; a timeout aimed only at that later response may leave this setup wait unbounded.
For Apache HttpClient 5.3.1, set the connection manager's defaults:
var connection = ConnectionConfig.custom()
.setConnectTimeout(Timeout.ofSeconds(5))
.setSocketTimeout(Timeout.ofSeconds(10))
.build();
var manager = PoolingHttpClientConnectionManagerBuilder.create()
.setDefaultConnectionConfig(connection)
.build();
var client = HttpClients.custom()
.setConnectionManager(manager)
.setProxy(new HttpHost("http", "proxy.example", 8080))
.build();Use the Apache HttpComponents 5 classes under org.apache.hc, with Timeout in the core5 utility package. Retain and close the client for its workload. For an isolated public HTTP test, a candidate from the HTTP proxy list supplies the endpoint; keep the destination steady when comparing timeouts.
| Limit | Wait addressed |
|---|---|
| Connect timeout | Connection establishment |
| Socket timeout | Default I/O inactivity, including the CONNECT exchange |
| Pool acquisition / application response | Other separately configured stages |
After CONNECT, TLS can need its own setup limit through HttpClient 5's TLS configuration. Also distinguish inactivity from a total deadline: intermittent bytes or repeated authentication exchanges can extend aggregate time. Use the application's supported deadline/cancellation policy for one whole-operation budget.