Skip to content

Fix an issue where NPE could be thrown when a request fails before ti… #3096

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

Merged
merged 3 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-6e30c31.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"category": "AWS SDK for Java v2",
"contributor": "",
"type": "bugfix",
"description": "Fixed an issue where NPE could be thrown when a request failed before API call timer started"
}
2 changes: 1 addition & 1 deletion .idea/inspectionProfiles/AWS_Java_SDK_2_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private Exception translatePipelineException(RequestExecutionContext context, Ex
// but before we called timeoutTracker.cancel(). Note that if hasExecuted() returns true, its guaranteed that
// the timeout tracker has set the interrupt flag, and if it returns false, it guarantees that it did not and
// will never set the interrupt flag.
if (context.apiCallTimeoutTracker().hasExecuted()) {
if (apiCallTimerExecuted(context)) {
// Clear the interrupt flag. Since we already have an exception from the call, which may contain information
// that's useful to the caller, just return that instead of an ApiCallTimeoutException.
Thread.interrupted();
Expand All @@ -133,7 +133,7 @@ private RuntimeException handleInterruptedException(RequestExecutionContext cont
if (e instanceof SdkInterruptedException) {
((SdkInterruptedException) e).getResponseStream().ifPresent(r -> invokeSafely(r::close));
}
if (context.apiCallTimeoutTracker().hasExecuted()) {
if (apiCallTimerExecuted(context)) {
// Clear the interrupt status
Thread.interrupted();
return generateApiCallTimeoutException(context);
Expand All @@ -143,6 +143,10 @@ private RuntimeException handleInterruptedException(RequestExecutionContext cont
return AbortedException.create("Thread was interrupted", e);
}

private static boolean apiCallTimerExecuted(RequestExecutionContext context) {
return context.apiCallTimeoutTracker() != null && context.apiCallTimeoutTracker().hasExecuted();
}

private ApiCallTimeoutException generateApiCallTimeoutException(RequestExecutionContext context) {
return ApiCallTimeoutException.create(
resolveTimeoutInMillis(context.requestConfig()::apiCallTimeout, apiCallTimeout));
Expand Down