aws-sdk-java-v2: Upload many files concurrently using Crt s3 java client: Exception thrown in S3MetaRequest#close, ignoring
Describe the bug
I am using 256 threads for concurrent uploads in spring boot and some requests are getting error logs
Expected Behavior
I don’t know, maybe there is no error thrown
Current Behavior
java.lang.NullPointerException: Cannot invoke "software.amazon.awssdk.crt.s3.S3MetaRequest.close()" because "this.metaRequest" is null
at software.amazon.awssdk.services.s3.internal.crt.S3CrtResponseHandlerAdapter.lambda$completeFutureAndCloseRequest$2(S3CrtResponseHandlerAdapter.java:113) ~[s3-2.19.4.jar!/:na]
at software.amazon.awssdk.utils.FunctionalUtils.runAndLogError(FunctionalUtils.java:40) ~[utils-2.19.4.jar!/:na]
at software.amazon.awssdk.services.s3.internal.crt.S3CrtResponseHandlerAdapter.completeFutureAndCloseRequest(S3CrtResponseHandlerAdapter.java:112) ~[s3-2.19.4.jar!/:na]
at software.amazon.awssdk.services.s3.internal.crt.S3CrtResponseHandlerAdapter.lambda$onSuccessfulResponseComplete$1(S3CrtResponseHandlerAdapter.java:106) ~[s3-2.19.4.jar!/:na]
at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source) ~[na:na]
at java.base/java.util.concurrent.CompletableFuture.uniWhenCompleteStage(Unknown Source) ~[na:na]
at java.base/java.util.concurrent.CompletableFuture.whenComplete(Unknown Source) ~[na:na]
at software.amazon.awssdk.services.s3.internal.crt.S3CrtResponseHandlerAdapter.onSuccessfulResponseComplete(S3CrtResponseHandlerAdapter.java:100) ~[s3-2.19.4.jar!/:na]
at software.amazon.awssdk.services.s3.internal.crt.S3CrtResponseHandlerAdapter.onFinished(S3CrtResponseHandlerAdapter.java:95) ~[s3-2.19.4.jar!/:na]
at software.amazon.awssdk.crt.s3.S3MetaRequestResponseHandlerNativeAdapter.onFinished(S3MetaRequestResponseHandlerNativeAdapter.java:24) ~[aws-crt-0.20.4.jar!/:0.20.4]
Reproduction Steps
CompletableFuture<PutObjectResponse> future = client.putObject(objectRequest,
AsyncRequestBody.fromFile(Paths.get(path))
);
future.whenComplete((resp, err) -> {
if (resp != null) {
System.out.println("Object uploaded. Details: " + resp);
} else {
// Handle error
err.printStackTrace();
}
});
future.join();
Possible Solution
No response
Additional Information/Context
No response
AWS Java SDK version used
2.19.4
JDK version used
openjdk version “17.0.4” 2022-07-19
Operating System and version
Ubuntu 16.04.7 LTS
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 15 (2 by maintainers)
We encountered this NullPointerException (NPE) due to a timing issue when receiving a very rapid response from S3. This typically happens during testing with small objects and a local S3 server. The problem arises because the native s3ClientMakeMetaRequest function invokes the responseHandler before the S3CrtAsyncHttpClient can properly set the metaRequest using the method responseHandler.metaRequest(s3MetaRequest).
To circumvent the NPE and prevent associated native resource leaks, we implemented a somewhat inelegant solution within the S3CrtResponseHandlerAdapter.completeFutureAndCloseRequest() method:
This workaround addresses the issue by waiting for metaRequest to become non-null before proceeding to close it, thus preventing the NPE and resource leakage.
In my opinion, it would be prudent to revisit this issue and consider alternative solutions.
I’ve seen the same issue with SDK
2.25.40and CRT0.29.18- I don’t have a simple repro of it, but it happens with local minio server. Here is the stack trace I could capture: