Skip to content

Commit 09c6ef5

Browse files
committed
Fixed an issue in AWS CRT-based S3 client where a GetObject request may hang if streaming failed mid request
1 parent ffc9ccc commit 09c6ef5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/crt/S3CrtResponseHandlerAdapter.java

+16
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ private S3MetaRequestWrapper s3MetaRequest() {
111111

112112
@Override
113113
public void onResponseHeaders(int statusCode, HttpHeader[] headers) {
114+
log.debug(() -> "Received response header with status code " + statusCode);
114115
// Note, we cannot call responseHandler.onHeaders() here because the response status code and headers may not represent
115116
// whether the request has succeeded or not (e.g. if this is for a HeadObject call that CRT calls under the hood). We
116117
// need to rely on onResponseBody/onFinished being called to determine this.
@@ -150,6 +151,7 @@ public int onResponseBody(ByteBuffer bodyBytesIn, long objectRangeStart, long ob
150151
@Override
151152
public void onFinished(S3FinishedResponseContext context) {
152153
int crtCode = context.getErrorCode();
154+
log.debug(() -> "Request finished with code: " + crtCode);
153155
if (crtCode != CRT.AWS_CRT_SUCCESS) {
154156
handleError(context);
155157
} else {
@@ -192,6 +194,19 @@ private void handleIoError(S3FinishedResponseContext context, int crtCode) {
192194
SdkClientException.create("Failed to send the request: " +
193195
CRT.awsErrorString(crtCode), cause);
194196
failResponseHandlerAndFuture(sdkClientException);
197+
notifyResponsePublisherErrorIfNeeded(sdkClientException);
198+
}
199+
200+
private void notifyResponsePublisherErrorIfNeeded(Throwable error) {
201+
if (responseHandlingInitiated) {
202+
responsePublisher.error(error).handle((ignore, throwable) -> {
203+
if (throwable != null) {
204+
log.error(() -> "Exception thrown in responsePublisher#error", throwable);
205+
return null;
206+
}
207+
return null;
208+
});
209+
}
195210
}
196211

197212
private void handleServiceError(int responseStatus, HttpHeader[] headers, byte[] errorPayload) {
@@ -204,6 +219,7 @@ private void handleServiceError(int responseStatus, HttpHeader[] headers, byte[]
204219
SdkClientException.create("Request failed during the transfer due to an error returned from S3");
205220
s3Exception.addSuppressed(sdkClientException);
206221
failResponseHandlerAndFuture(s3Exception);
222+
notifyResponsePublisherErrorIfNeeded(s3Exception);
207223
} else {
208224
initiateResponseHandling(errorResponse.build());
209225
onErrorResponseComplete(errorPayload);

0 commit comments

Comments
 (0)