aws-sdk-java-v2: NPE in TransformingAsyncResponseHandler#onError
Describe the bug
From time to time, we get an ERROR log from TransformingAsyncResponseHandler telling us that there was an NPE. It does not affect our app in any way, however it feels that it shouldn’t throw that.
Expected Behavior
No log record nor NPE.
Current Behavior
We get this log statement after NPE has been raised in aws sdk core
5352c77fa1b2:2020-05-04 09:36:31,681 [speculation-executor-1] ERROR s.a.a.c.i.h.BaseAsyncClientHandler - Error thrown from TransformingAsyncResponseHandler#onError, ignoring.
5352c77fa1b2:java.lang.NullPointerException: null
5352c77fa1b2: at software.amazon.awssdk.core.internal.http.async.AsyncResponseHandler.onError(AsyncResponseHandler.java:76)
5352c77fa1b2: at software.amazon.awssdk.core.internal.http.async.CombinedResponseAsyncHttpResponseHandler.onError(CombinedResponseAsyncHttpResponseHandler.java:70)
5352c77fa1b2: at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.lambda$doExecute$3(BaseAsyncClientHandler.java:223)
5352c77fa1b2: at software.amazon.awssdk.utils.FunctionalUtils.runAndLogError(FunctionalUtils.java:40)
5352c77fa1b2: at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.doExecute(BaseAsyncClientHandler.java:220)
5352c77fa1b2: at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.execute(BaseAsyncClientHandler.java:86)
5352c77fa1b2: at software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler.execute(AwsAsyncClientHandler.java:52)
5352c77fa1b2: at software.amazon.awssdk.services.dynamodb.DefaultDynamoDbAsyncClient.query(DefaultDynamoDbAsyncClient.java:2707)
...
(our code)
Steps to Reproduce
I don’t know a deterministic way.
Possible Solution
I realize that the NPE comes from AsyncResponseHandler:
@Override
public void onError(Throwable err) {
streamFuture.completeExceptionally(err);
}
where streamFuture is null, as prepare() has not been called yet.
Context
The context is we’re doing an async requests to ddb, and for some requests we may cancel them via future.cancel(). Apart from that we’re not doing anything special with our query requests.
Your Environment
AWS-SDK: 2.13.8 Java: 12
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 19
- Comments: 15 (2 by maintainers)
Commits related to this issue
- Fixed an issue where "Error thrown from TransformingAsyncResponseHandler#onError, ignoring" could be logged during an unrelated failure. Fixes https://github.com/aws/aws-sdk-java-v2/issues/1812 — committed to aws/aws-sdk-java-v2 by millems 6 years ago
- Merge pull request #1812 from aws/dongie/connectchat-japicmp Exclude connectchat from japicmp check — committed to aws/aws-sdk-java-v2 by dagnir 5 years ago
Strange that this is still not fixed. I believe the problem is here in the
BaseAsyncClientHandler.doExecute():That
new AsyncAfterTransmissionInterceptorCallingResponseHandler()is neverprepare()d.Unfortunately we cannot override
AwsAsyncClientHandlerto workaround the problem:I really would like to know the reason behind my failure instead of just plain NPE…
Thanks for understanding!
Hello @jenshoffmann1331 ,
Thank you very much for reaching out. We unfortunately do not have any current publicly available timeline. I will bring this issue back up for discussion. Are you able to work around this?
Best,
Yasmine
Hey AWS. This issue is open for about 3 years and we are still affected by this in one of our production systems. Can you please give us a timeline for when this will be fixed? Thank you so much!
For anyone else who landed here that is also using Reactor (and was confused by the logs they were seeing) or who might be incorrectly using the SDK;
I had code similar to this:
The issue is that
Mono.fromFuture(future)will not re-execute the already completed future (which failed). Subsequent retries will then also fail for the same reason.The above code uses
Mono.defer()to delay the creation of theCompletableFutureand allows retries to create a new future on each attempt.Now of course this does not fix the underlying issue with the SDK which is logging a misleading/unnecessary error - just thought this would be helpful for others who might also have been using the SDK wrong.
I think I have a patch for that though! I was able to stop the NullPointerException but I need to write some tests and validate my fix isn’t breaking anything first.
This reproduced the issue consistently for me:
I would expect this to throw an AbortedException/CancellationException/InterruptedException however due to the bug it’s a NullPointerException.
I am also seeing this error when attempting to call
SqsAsyncClient.receiveMessage(). In my case, the mesage is not received. The error doesn’t occur in in v2.12.0.