Repository navigation
Description
Summary
Requesting reconsideration to backport the fix from HTTPCLIENT-2421 (PR #830, commit f069c136445103bb0691b205199bdfa703e6160b) to the active 5.6.x maintenance branch (for 5.6.6), and ideally to 5.5.3 if another 5.5.x patch release is ever cut.
In PR #830, backporting to 5.6.x was initially declined as a potential "behavioral change". However, git history shows that ignoring Retry-After when it exceeds RequestConfig#responseTimeout was the established 5.x behavior for four years (5.1.0 through 5.5.0), originally implemented in HTTPCLIENT-2141 / #3019, and was inadvertently broken in patch release 5.5.1 during a refactoring.
Backporting f069c136 to 5.6.x therefore restores the documented 5.1–5.5.0 contract rather than introducing a new behavior.
Git Archaeology: How the regression was introduced in 5.5.1
-
5.1.0–5.5.0(expected behavior, HTTPCLIENT-2141 / #3019):
HttpRequestRetryExec(andAsyncHttpRequestRetryExec) explicitly checked the effective retry interval returned byretryStrategy.getRetryInterval(...)(including any parsedRetry-Afterheader) againstRequestConfig#responseTimeout:final TimeValue nextInterval = retryStrategy.getRetryInterval(response, execCount, context); // Make sure the retry interval does not exceed the response timeout if (TimeValue.isPositive(nextInterval)) { final RequestConfig requestConfig = context.getRequestConfigOrDefault(); final Timeout responseTimeout = requestConfig.getResponseTimeout(); if (responseTimeout != null && nextInterval.compareTo(responseTimeout) > 0) { return response; } }
This contract was covered by
TestHttpRequestRetryExec#testRetryIntervalGreaterResponseTimeout()(nextInterval = 5s > responseTimeout = 3s-> no retry, response returned immediately). -
5.5.1&5.6.x(PR #672, commitaab688bb4aon5.5.x/e02c106d54on5.6.x):
While moving theresponseTimeoutcheck fromHttpRequestRetryExecintoDefaultHttpRequestRetryStrategy#retryRequest(HttpResponse, int, HttpContext),nextIntervalwas replaced by the constant fielddefaultRetryInterval(1 secondby default):final Timeout responseTimeout = requestConfig.getResponseTimeout(); if (responseTimeout != null && defaultRetryInterval.compareTo(responseTimeout) > 0) { return false; }
In the same commit:
TestHttpRequestRetryExec#testRetryIntervalGreaterResponseTimeout()was removed.- The replacement test
TestDefaultHttpRequestRetryStrategy#testRetryRequestWithResponseTimeout()tested a503response without aRetry-Afterheader (1svs1234ms/1233ms), which masked the regression wheneverRetry-Afteris present.
-
5.7-alpha1(PR #830, commitf069c13644):
Restored the check againstgetRetryInterval(response, execCount, context)and addedtestRetryRequestWithResponseTimeoutAndRetryAfterHeader(), but only onmaster(5.7-alpha1/5.7-beta1).
Minimal Reproduction / Concrete Example
Configure a classic CloseableHttpClient with responseTimeout = 6 seconds (default DefaultHttpRequestRetryStrategy.INSTANCE, where defaultRetryInterval = 1s):
- Client sends a request with
RequestConfig.custom().setResponseTimeout(Timeout.ofSeconds(6)).build(). - Upstream CDN / WAF rate-limiter immediately responds (
~100 ms):HTTP/1.1 429 Too Many Requests Retry-After: 59
DefaultHttpRequestRetryStrategy#retryRequestevaluates:
defaultRetryInterval (1s) > responseTimeout (6s)->false, so it returnstrue.HttpRequestRetryExeccloses the first response (response.close()), callsgetRetryInterval(...)which parsesRetry-After: 59->59 seconds, and executespause(delay)->Thread.sleep(59_000)(with no open socket, soSO_TIMEOUTcannot interrupt it).- Actual (
5.5.1–5.5.2,5.6.0–5.6.5): Calling thread blocks for ~60 seconds despiteresponseTimeout = 6s, then re-executes the request. - Expected (
5.1.0–5.5.0,5.7-alpha1+):retryInterval (59s) > responseTimeout (6s)-> returnsfalse, returning the429response immediately in~100 ms.
Why backporting to 5.6.x matters for the Java ecosystem
- Severe production impact under CDN/WAF rate-limiting: Standard edge WAFs (e.g., Cloudflare rate-limiting rules) routinely attach
Retry-After: 60(or evenRetry-After: 300/3600) toHTTP 429responses. In synchronous worker pools configured with strict timeouts (e.g.,5–6s), sleeping every worker thread for60s+insideHttpRequestRetryExecinstantaneously exhausts thread pools and stalls upstream message consumers—and becauseorg.apache.hc.client5logging defaults toWARN/ERRORin frameworks like Spring Boot, the silentThread.sleeplooks like a socket hang. - Framework dependency policies: Spring Boot
4.1.xtracks the5.6.xline (5.6.5currently) and never upgrades minor dependency versions within a release line (3.5.xand4.0.xtrack5.5.2). Without a backport to5.6.6, the current GA line of HttpClient 5—and the entire Spring Boot4.1.xecosystem—remains exposed until5.7GA and future framework majors ship. - Zero-conflict cherry-pick: Commit
f069c136445103bb0691b205199bdfa703e6160bapplies cleanly onto5.6.x(DefaultHttpRequestRetryStrategy.javaandTestDefaultHttpRequestRetryStrategy.javaare identical in this section).
I am opening a follow-up PR right now with the clean cherry-pick -x of f069c136445103bb0691b205199bdfa703e6160b targeting 5.6.x for your review.
Activity
ok2c commentedon Nov 30, 2026
@xcapdevila The
HttpRequestRetryStrategyinterface is broken and has been causing grief for a long time. It needs to be deprecated and replaced with a new one. I hoped that could wait until5.8but now likely will likely must be done before5.7is outI can merge #3326 if you absolutely insist. However, given how simple
HttpRequestRetryStrategyis, one can easily have a custom implementation with whatever behavior one considers correct or appropriate. This is the reason we provide those strategy interfaces in the first place because we just cannot make everyone happy.xcapdevila commentedon Nov 30, 2026
Hi @ok2c , yes, I’d appreciate it if you could merge #3326 into
5.6.x.With a six-second
responseTimeoutandRetry-After: 59, the default strategy approves the retry based on a one-second interval, then waits 59 seconds. The check should use the delay the client will actually apply.A custom strategy is a useful workaround in the meantime. The backport restores the earlier behavior for applications using the default strategy.
Thanks for taking another look at this!
ok2c commentedon Nov 30, 2026
@xcapdevila I am sorry but I have to say it again - custom strategies are not a work-around. We just cannot make everyone happy. People are expected to implement strategies specific to their applications and their needs.
RequestConfig#responseTimeoutis a hint. It may or may not have an effect depending on many things: HTTP version, TLS, etc. The defaultHttpRequestRetryStrategynot respecting it is not a defect.xcapdevila commentedon Nov 30, 2026
Thanks for clarifying, @ok2c . My concern is with the check the default retry strategy already makes in
5.6.x. When it compares a retry delay againstresponseTimeout, I’d expect it to use the delay the client will actually wait, includingRetry-Afterwhen it applies. In this example, that would mean returning the429we already received instead of waiting 59 seconds for a retry.That’s the earlier behavior I’d like to restore with #3326. Thanks for considering the backport.
ok2c commentedon Nov 30, 2026
@xcapdevila Anyway, feel free to review #3328