Skip to content

Commit 7d1830b

Browse files
authored
Add a workaround for connection acquire issue (#6808)
* 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. * Add changelog
1 parent 9d89736 commit 7d1830b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "Apache 5 HTTP Client",
4+
"contributor": "",
5+
"description": "Fixed an issue in the Apache 5 HTTP client where requests could fail with `\"Endpoint not acquired / already released\"`. These failures are now converted to retryable I/O errors."
6+
}

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/Apache5HttpClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ private HttpExecuteResponse execute(HttpUriRequestBase apacheRequest, MetricColl
291291
HttpHost target = determineTarget(apacheRequest);
292292
ClassicHttpResponse httpResponse = httpClient.executeOpen(target, apacheRequest, localRequestContext);
293293
return createResponse(httpResponse, apacheRequest);
294+
} catch (IllegalStateException e) {
295+
// TODO: remove this when a permanent fix is made upstream
296+
// This is a workaround for a race condition where a connection is not properly acquired when httpClient attempts
297+
// to execute a request on a connection from the pool. For now, we rethrow this as an IOException so upper layers
298+
// have a chance to retry if possible
299+
if ("Endpoint not acquired / already released".equals(e.getMessage())) {
300+
throw new IOException("Failed to execute HTTP request", e);
301+
}
302+
throw e;
294303
} finally {
295304
THREAD_LOCAL_REQUEST_METRIC_COLLECTOR.remove();
296305
}

0 commit comments

Comments
 (0)