Skip to content

Commit 8c767b9

Browse files
authored
Fixed the issue where AWS CRT-based S3 client was eagerly buffering data before the underlying CRT component was able to handle it. (#3800)
1 parent 02860e6 commit 8c767b9

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS CRT-based S3 client",
4+
"contributor": "",
5+
"description": "Fixed the issue where AWS CRT-based S3 client was eagerly buffering data before the underlying CRT component was able to handle it. See [#3726](https://github.com/aws/aws-sdk-java-v2/issues/3726)"
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS CRT-based S3 client",
4+
"contributor": "",
5+
"description": "Reduced the buffer used to upload object from 16MB to 1MB."
6+
}

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.awssdk.services.s3.internal.crt;
1717

1818
import java.nio.ByteBuffer;
19+
import java.util.concurrent.atomic.AtomicBoolean;
1920
import software.amazon.awssdk.annotations.SdkInternalApi;
2021
import software.amazon.awssdk.crt.http.HttpRequestBodyStream;
2122
import software.amazon.awssdk.http.async.SdkHttpContentPublisher;
@@ -26,19 +27,23 @@
2627
*/
2728
@SdkInternalApi
2829
public final class S3CrtRequestBodyStreamAdapter implements HttpRequestBodyStream {
29-
private static final long MINIMUM_BYTES_BUFFERED = 16 * 1024 * 1024L;
30+
private static final long MINIMUM_BYTES_BUFFERED = 1024 * 1024L;
3031
private final SdkHttpContentPublisher bodyPublisher;
3132
private final ByteBufferStoringSubscriber requestBodySubscriber;
3233

34+
private final AtomicBoolean subscribed = new AtomicBoolean(false);
3335

3436
public S3CrtRequestBodyStreamAdapter(SdkHttpContentPublisher bodyPublisher) {
3537
this.bodyPublisher = bodyPublisher;
3638
this.requestBodySubscriber = new ByteBufferStoringSubscriber(MINIMUM_BYTES_BUFFERED);
37-
bodyPublisher.subscribe(requestBodySubscriber);
3839
}
3940

4041
@Override
4142
public boolean sendRequestBody(ByteBuffer outBuffer) {
43+
if (subscribed.compareAndSet(false, true)) {
44+
bodyPublisher.subscribe(requestBodySubscriber);
45+
}
46+
4247
// blocking here because CRT S3 requires the buffer to be completely filled
4348
return requestBodySubscriber.blockingTransferTo(outBuffer) == ByteBufferStoringSubscriber.TransferResult.END_OF_STREAM;
4449
}

0 commit comments

Comments
 (0)