Skip to content

Commit ee51283

Browse files
authored
Fix an issue that could result in resource leak when sending request fails due to errors such as invalid request. (#3719)
1 parent d66db22 commit ee51283

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
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": "AWS CRT HTTP Client",
4+
"contributor": "",
5+
"description": "Fix an issue that could result in resource leak when sending request fails due to errors such as invalid request."
6+
}

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/internal/CrtRequestExecutor.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public CompletableFuture<Void> execute(CrtRequestContext executionContext) {
7373

7474
// If we didn't get a connection for some reason, fail the request
7575
if (throwable != null) {
76-
reportFailure(new IOException("An exception occurred when acquiring a connection", throwable),
76+
reportFailure(crtConn,
77+
new IOException("An exception occurred when acquiring a connection", throwable),
7778
requestFuture,
7879
asyncRequest.responseHandler());
7980
return;
@@ -121,12 +122,13 @@ private void executeRequest(CrtRequestContext executionContext,
121122
// it's semantically an IOException anyway.
122123
toThrow = new IOException(e);
123124
}
124-
reportFailure(toThrow,
125+
reportFailure(crtConn,
126+
toThrow,
125127
requestFuture,
126128
asyncRequest.responseHandler());
127129
} catch (IllegalStateException | CrtRuntimeException e) {
128130
// CRT throws IllegalStateException if the connection is closed
129-
reportFailure(new IOException("An exception occurred when making the request", e),
131+
reportFailure(crtConn, new IOException("An exception occurred when making the request", e),
130132
requestFuture,
131133
asyncRequest.responseHandler());
132134
}
@@ -156,9 +158,14 @@ private CompletableFuture<Void> createExecutionFuture(AsyncExecuteRequest reques
156158
/**
157159
* Notify the provided response handler and future of the failure.
158160
*/
159-
private void reportFailure(Throwable cause,
161+
private void reportFailure(HttpClientConnection crtConn,
162+
Throwable cause,
160163
CompletableFuture<Void> executeFuture,
161164
SdkAsyncHttpResponseHandler responseHandler) {
165+
if (crtConn != null) {
166+
crtConn.close();
167+
}
168+
162169
try {
163170
responseHandler.onError(cause);
164171
} catch (Exception e) {

http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/H1ServerBehaviorTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import org.junit.jupiter.api.AfterAll;
2121
import org.junit.jupiter.api.BeforeAll;
22-
import org.junit.jupiter.api.Test;
2322
import software.amazon.awssdk.crt.CrtResource;
2423
import software.amazon.awssdk.crt.Log;
2524
import software.amazon.awssdk.http.SdkAsyncHttpClientH1TestSuite;
@@ -47,9 +46,4 @@ protected SdkAsyncHttpClient setupClient() {
4746
return AwsCrtAsyncHttpClient.builder()
4847
.buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, true).build());
4948
}
50-
51-
@Test
52-
// TODO: Remove this override. Temporarily disabling test because it's causing memory leak
53-
public void naughtyHeaderCharactersDoNotGetToServer() {
54-
}
5549
}

0 commit comments

Comments
 (0)