Skip to content

AsyncResponseHandler.onError(Throwable) throws an NPE if called before prepare(). #2251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joelc opened this issue Jan 21, 2021 · 4 comments
Closed
Labels
bug This issue is a bug. p3 This is a minor priority issue

Comments

@joelc
Copy link

joelc commented Jan 21, 2021

Describe the bug

software.amazon.awssdk.core.internal.http.async.AsyncResponseHandler.onError(Throwable) throws an NPE if called before prepare().

This causes the Throwable passed to onError to be swallowed.

Expected Behavior

Do not swallow the provided Throwable. Callers have no way of knowing what the actual cause was.

Current Behavior

It throws an NPE and swallows the provided Throwable.

2021-01-21 19:37:38,564 [HOST] ERROR [FunctionalUtils.java: 42] - 0 0 - Error thrown from TransformingAsyncResponseHandler#onError, ignoring.
java.lang.NullPointerException: null
	at software.amazon.awssdk.core.internal.http.async.AsyncResponseHandler.onError(AsyncResponseHandler.java:76)
	at software.amazon.awssdk.core.internal.http.async.CombinedResponseAsyncHttpResponseHandler.onError(CombinedResponseAsyncHttpResponseHandler.java:70)
	at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.lambda$doExecute$5(BaseAsyncClientHandler.java:230)
	at software.amazon.awssdk.utils.FunctionalUtils.runAndLogError(FunctionalUtils.java:40)
	at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.doExecute(BaseAsyncClientHandler.java:227)
	at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.lambda$execute$1(BaseAsyncClientHandler.java:90)
	at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.measureApiCallSuccess(BaseAsyncClientHandler.java:275)
	at software.amazon.awssdk.core.internal.handler.BaseAsyncClientHandler.execute(BaseAsyncClientHandler.java:75)
	at software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler.execute(AwsAsyncClientHandler.java:52)
	at software.amazon.awssdk.services.sns.DefaultSnsAsyncClient.publish(DefaultSnsAsyncClient.java:2281)

Steps to Reproduce

This unit test throws an NPE and there's no trace of the NumberFormatException that was provided to onError; it's written to pass with the code in "Possible Solution" below.

@Test
public void shouldNotSwallowThrowablePassedToOnErrorBeforePrepare() {
    // given
    AsyncResponseHandler sut = new AsyncResponseHandler(null, null, null);

    // when
    ThrowingCallable tc = () -> sut.onError(new NumberFormatException());

    // then
    assertThatThrownBy(tc).isInstanceOf(IllegalStateException.class)
                          .hasCauseInstanceOf(NumberFormatException.class);
}

Possible Solution

Do not throw an NPE that swallows err:

@Override
public void onError(Throwable err) {
    if (streamFuture == null) {
        throw new IllegalStateException("onError called before prepare", err);
    }

    streamFuture.completeExceptionally(err);
}

Context

Under high load, we have some software that's misbehaving. It's causing (we think) requests to be canceled before they're prepared for execution. With this onError implementation, we get to see the underlying exception in our logs.

Your Environment

  • AWS Java SDK version used: 2.15.*
  • JDK version used: java version "11.0.6" 2020-01-14 LTS
  • Operating System and version: Various RHELs
@joelc joelc added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 21, 2021
@debora-ito
Copy link
Member

Hi @joelc sorry for the delayed response. Looks like a bug, marking as a bug.

@debora-ito debora-ito removed the needs-triage This issue or PR still needs to be triaged. label Feb 3, 2021
@debora-ito
Copy link
Member

Related to #1812.

aws-sdk-java-automation added a commit that referenced this issue Nov 11, 2022
…07f8ce26e

Pull request: release <- staging/b0cf8b32-2b55-46f9-9c50-0ff07f8ce26e
@yasminetalby yasminetalby added the p3 This is a minor priority issue label Nov 12, 2022
@debora-ito
Copy link
Member

This should be fixed by this commit: https://github.com/aws/aws-sdk-java-v2/pull/4567/files#diff-18f6745a85126bf1b23736af8857375b8e7328956262a3d7f08e5bb5b7684303.

The fix is included in SDK version 2.21.1.

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

3 participants