aws-amplify / aws-sdk-android

AWS SDK for Android. For more information, see our web site:
https://docs.amplify.aws
Other
1.02k stars 548 forks source link

Why would AWS SDK Android default retry policy omit InterruptedIOExceptions by default? #2178

Open kevvurs opened 3 years ago

kevvurs commented 3 years ago

State your question What's the rationale for explicitly not retrying connection failures in the default policy in AWS SDK Android?

As a user of AWS SDK Android, I was surprised to see the default retry condition specifically excludes exceptions from being retried if they are caused by InterruptedIOException.

A super common issue I have seen for Android is poor connectivity, leading to SocketTimeoutException, occurring when the device tries to access AWS resources. Since SocketTimeoutException is a subclass of InterruptedIOException, related connection issues are not retried with the default AWS SDK retry policy.

Which AWS Services are you utilizing? STS and SSM

Provide code snippets (if applicable) SDKDefaultRetryCondition:

public static class SDKDefaultRetryCondition implements RetryPolicy.RetryCondition {
    @Override
    public boolean shouldRetry(AmazonWebServiceRequest originalRequest,
            AmazonClientException exception,
            int retriesAttempted) {

        // Always retry on client exceptions caused by IOException, unless
        // it's caused by a thread interruption
        if ((exception.getCause() instanceof IOException)
                && !(exception.getCause() instanceof InterruptedIOException))
            return true;
        ...
    }
}

Environment(please complete the following information): !(exception.getCause() instanceof InterruptedIOException is in your main branch and was excluded from retry conditions 5 years ago.

Device Information (please complete the following information): Any

jamesonwilliams commented 3 years ago

Hi @kevvurs. I agree that this is suspicious default behavior. Our team will evaluate options.

Meanwhile, please note that you can supply your own RetryPolicy to most any client you configure in the SDK. To do, provide one to a ClientConfiguration object while constructing an SDK client:

val policy = RetryPolicy(retryCondition, backOffStrategy, 3, false)
val config = ClientConfiguration().withRetryPolicy(policy)
val s3 = AmazonS3Client(config)

See:

  1. RetryPolicy
  2. PredefinedRetryPolicies
kevvurs commented 3 years ago

Thanks for the update. I did implement a custom RP to resolve the issue. The exclusion of STE from the default policy was a "gotcha" for me though.