From d71904bcc144dd0388214b3ec621b5a456943ca1 Mon Sep 17 00:00:00 2001 From: Dongie Agnir Date: Thu, 19 Mar 2026 13:43:24 -0700 Subject: [PATCH] Add a workaround for connection acquire issue There appears to be an issue in rare circumstances where a connection acquire fails so that no connection is leased from the pool, and validation of the connection subsequently fails, causing the underlying HTTP client to throw. This adds a workaround for this issue by rethrowing the exception wrapped in an IOException to at least give the upper layer an opportunity to retry the request. --- .../amazon/awssdk/http/apache5/Apache5HttpClient.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/Apache5HttpClient.java b/http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/Apache5HttpClient.java index ec75cf1ed785..a07eb5f107c0 100644 --- a/http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/Apache5HttpClient.java +++ b/http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/Apache5HttpClient.java @@ -291,6 +291,15 @@ private HttpExecuteResponse execute(HttpUriRequestBase apacheRequest, MetricColl HttpHost target = determineTarget(apacheRequest); ClassicHttpResponse httpResponse = httpClient.executeOpen(target, apacheRequest, localRequestContext); return createResponse(httpResponse, apacheRequest); + } catch (IllegalStateException e) { + // TODO: remove this when a permanent fix is made upstream + // This is a workaround for a race condition where a connection is not properly acquired when httpClient attempts + // to execute a request on a connection from the pool. For now, we rethrow this as an IOException so upper layers + // have a chance to retry if possible + if ("Endpoint not acquired / already released".equals(e.getMessage())) { + throw new IOException("Failed to execute HTTP request", e); + } + throw e; } finally { THREAD_LOCAL_REQUEST_METRIC_COLLECTOR.remove(); }