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(); }