Description
Describe the bug
Using S3AsyncClient.builder() causes TransferListener not to work as expected. TransferListener only works properly when using .crtBuilder()
Expected Behavior
TransferListener to function the same as S3AsyncClient.crtBuilder() when using S3AsyncClient.builder()
Current Behavior
When S3AsyncClient is built using the below configuration, everything functions as expected when transferring a file via UploadFileRequest:
S3AsyncClient s3AsyncClient2 = S3AsyncClient.crtBuilder()
.credentialsProvider(provider)
.region(Region.EU_WEST_2)
.build();
The request:
UploadFileRequest uploadFileRequest =
UploadFileRequest.builder()
.putObjectRequest(b -> b.bucket(bucket).key(s3Key).contentType(file.getContentType()))
.addTransferListener(new CustomTransferListener())
.source(convFile)
.build();
s3TransferManager.uploadFile(uploadFileRequest);
However, if I want to use a custom http client using S3AsyncClient.builder()
instead of .crtBuilder()
as shown in the documentation, it doesn't function as expected. Even if I use no custom .httpClient and simply use .builder(), the same, broken behaviour occurs as seen in the reproduction steps.
S3AsyncClient s3AsyncClient = S3AsyncClient.builder()
.httpClient(
AwsCrtAsyncHttpClient.builder()
.maxConcurrency(100)
.connectionMaxIdleTime(Duration.ofHours(1))
.connectionTimeout(Duration.ofHours(1))
.build())
.credentialsProvider(provider)
.region(Region.EU_WEST_2)
.build();
TransferListener bytesTransferred method jumps to 1.0 when calling context.progressSnapshot().ratioTransferred()
extremely quickly (within a few ms), sits at 1.0 with no other calls until the file is uploaded, then completes. This is the same behaviour seen by these two issues (although these seem to occur due to different issues): #4114 and #3670.
I have tried 3 different configs with all three have the same outcome with the ratio jumping very quickly to 1.0:
- No custom .httpClient declared (however using S3AsyncClient.builder())
- The config posted above
- Using NettyNioAsyncHttpClient as seen below.
S3AsyncClient s3AsyncClient = S3AsyncClient.builder()
.httpClient(NettyNioAsyncHttpClient.builder()
.maxConcurrency(500)
.maxPendingConnectionAcquires(10000)
.writeTimeout(Duration.ofHours(1))
.connectionMaxIdleTime(Duration.ofHours(1))
.connectionTimeout(Duration.ofHours(1))
.connectionAcquisitionTimeout(Duration.ofHours(1))
.connectionTimeToLive(Duration.ofHours(1))
.readTimeout(Duration.ofHours(1)).build())
.credentialsProvider(provider)
.region(Region.EU_WEST_2)
.build();
Reproduction Steps
S3AsyncClient s3AsyncClient2 = S3AsyncClient.builder()
.credentialsProvider(provider)
.region(Region.EU_WEST_2)
.build();
S3TransferManager transferManager =
S3TransferManager.builder()
.s3Client(s3AsyncClient2)
.build();
UploadFileRequest uploadFileRequest =
UploadFileRequest.builder()
.putObjectRequest(b -> b.bucket(bucket).key(key))
.addTransferListener(LoggingTransferListener.create())
.source(file)
.build();
transferManager.uploadFile(uploadFileRequest);
Observe transfer listener jumping to 100% within milliseconds, despite the upload taking much longer (when a large file is used)
Possible Solution
No response
Additional Information/Context
No response
AWS Java SDK version used
2.20.161
JDK version used
17.0.5
Operating System and version
Windows 10 Pro Version 10.0.19045 Build 19045