Skip to content

[Regression in 5.5.1 / 5.6.x] Backport HTTPCLIENT-2421 to 5.6.x (and 5.5.x if possible): Retry-After header bypasses RequestConfig#responseTimeout #3325

Done

Description

@xcapdevila

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

  1. 5.1.0 – 5.5.0 (expected behavior, HTTPCLIENT-2141 / #3019):
    HttpRequestRetryExec (and AsyncHttpRequestRetryExec) explicitly checked the effective retry interval returned by retryStrategy.getRetryInterval(...) (including any parsed Retry-After header) against RequestConfig#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).

  2. 5.5.1 & 5.6.x (PR #672, commit aab688bb4a on 5.5.x / e02c106d54 on 5.6.x):
    While moving the responseTimeout check from HttpRequestRetryExec into DefaultHttpRequestRetryStrategy#retryRequest(HttpResponse, int, HttpContext), nextInterval was replaced by the constant field defaultRetryInterval (1 second by 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 a 503 response without a Retry-After header (1s vs 1234ms/1233ms), which masked the regression whenever Retry-After is present.
  3. 5.7-alpha1 (PR #830, commit f069c13644):
    Restored the check against getRetryInterval(response, execCount, context) and added testRetryRequestWithResponseTimeoutAndRetryAfterHeader(), but only on master (5.7-alpha1 / 5.7-beta1).


Minimal Reproduction / Concrete Example

Configure a classic CloseableHttpClient with responseTimeout = 6 seconds (default DefaultHttpRequestRetryStrategy.INSTANCE, where defaultRetryInterval = 1s):

  1. Client sends a request with RequestConfig.custom().setResponseTimeout(Timeout.ofSeconds(6)).build().
  2. Upstream CDN / WAF rate-limiter immediately responds (~100 ms):
    HTTP/1.1 429 Too Many Requests
    Retry-After: 59
  3. DefaultHttpRequestRetryStrategy#retryRequest evaluates:
    defaultRetryInterval (1s) > responseTimeout (6s) -> false, so it returns true.
  4. HttpRequestRetryExec closes the first response (response.close()), calls getRetryInterval(...) which parses Retry-After: 59 -> 59 seconds, and executes pause(delay) -> Thread.sleep(59_000) (with no open socket, so SO_TIMEOUT cannot interrupt it).
  5. Actual (5.5.1–5.5.2, 5.6.0–5.6.5): Calling thread blocks for ~60 seconds despite responseTimeout = 6s, then re-executes the request.
  6. Expected (5.1.0–5.5.0, 5.7-alpha1+): retryInterval (59s) > responseTimeout (6s) -> returns false, returning the 429 response 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 even Retry-After: 300 / 3600) to HTTP 429 responses. In synchronous worker pools configured with strict timeouts (e.g., 5–6s), sleeping every worker thread for 60s+ inside HttpRequestRetryExec instantaneously exhausts thread pools and stalls upstream message consumers—and because org.apache.hc.client5 logging defaults to WARN/ERROR in frameworks like Spring Boot, the silent Thread.sleep looks like a socket hang.
  • Framework dependency policies: Spring Boot 4.1.x tracks the 5.6.x line (5.6.5 currently) and never upgrades minor dependency versions within a release line (3.5.x and 4.0.x track 5.5.2). Without a backport to 5.6.6, the current GA line of HttpClient 5—and the entire Spring Boot 4.1.x ecosystem—remains exposed until 5.7 GA and future framework majors ship.
  • Zero-conflict cherry-pick: Commit f069c136445103bb0691b205199bdfa703e6160b applies cleanly onto 5.6.x (DefaultHttpRequestRetryStrategy.java and TestDefaultHttpRequestRetryStrategy.java are 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

  1. ok2c commented on Nov 30, 2026

    @ok2c
    Member

    @xcapdevila The HttpRequestRetryStrategy interface 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 until 5.8 but now likely will likely must be done before 5.7 is out

    I can merge #3326 if you absolutely insist. However, given how simple HttpRequestRetryStrategy is, 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.

  2. xcapdevila commented on Nov 30, 2026

    @xcapdevila
    Author

    Hi @ok2c , yes, I’d appreciate it if you could merge #3326 into 5.6.x.

    With a six-second responseTimeout and Retry-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!

  3. ok2c commented on Nov 30, 2026

    @ok2c
    Member

    A custom strategy is a useful workaround

    @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#responseTimeout is a hint. It may or may not have an effect depending on many things: HTTP version, TLS, etc. The default HttpRequestRetryStrategy not respecting it is not a defect.

  4. xcapdevila commented on Nov 30, 2026

    @xcapdevila
    Author

    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 against responseTimeout, I’d expect it to use the delay the client will actually wait, including Retry-After when it applies. In this example, that would mean returning the 429 we 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.

  5. ok2c commented on Nov 30, 2026

    @ok2c
    Member

    @xcapdevila Anyway, feel free to review #3328

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions