Skip to content
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

Fixed the invocation of refresh! method on SharedCredentials #2686

Merged
merged 3 commits into from
Apr 12, 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
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Issue - Don't call `refresh!` on non-refreshable `Credentials` when retrying errors (#2685).

3.130.0 (2022-03-11)
------------------

Expand Down
14 changes: 12 additions & 2 deletions gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,17 @@ def exponential_backoff(retries)

def retry_request(context, error)
context.retries += 1
context.config.credentials.refresh! if error.expired_credentials?
context.config.credentials.refresh! if refresh_credentials?(context, error)
context.http_request.body.rewind
context.http_response.reset
call(context)
end

def refresh_credentials?(context, error)
error.expired_credentials? &&
context.config.credentials.respond_to?(:refresh!)
end

def add_retry_headers(context)
request_pairs = {
'attempt' => context.retries,
Expand Down Expand Up @@ -383,7 +388,7 @@ def retry_if_possible(response, error_inspector)
def retry_request(context, error)
delay_retry(context)
context.retries += 1
context.config.credentials.refresh! if error.expired_credentials?
context.config.credentials.refresh! if refresh_credentials?(context, error)
context.http_request.body.rewind
context.http_response.reset
call(context)
Expand All @@ -399,6 +404,11 @@ def should_retry?(context, error)
response_truncatable?(context)
end

def refresh_credentials?(context, error)
error.expired_credentials? &&
context.config.credentials.respond_to?(:refresh!)
end

def retry_limit(context)
context.config.retry_limit
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative '../../spec_helper'
require_relative '../../retry_errors_helper'

module Aws
module Plugins
Expand Down Expand Up @@ -207,12 +208,20 @@ module Plugins
end

it 'retries if creds expire and are refreshable' do
# Note: this adds the refresh! method to credentials
expect(credentials).to receive(:refresh!).exactly(3).times
resp.error = RetryErrorsSvc::Errors::AuthFailure.new(nil, nil)
handle { |_context| resp }
expect(resp.context.retries).to eq(3)
end

it 'does not call refresh! when error is expired credentials and clock skew' do
resp.error = RetryErrorsSvc::Errors::RequestExpired.new(nil, nil)
resp.context.http_response.headers['date'] = (Time.now + 10*60).iso8601
handle { |_context| resp }
expect(resp.context.retries).to eq(1)
end

it 'retries if endpoint discovery error is detected' do
config.api.endpoint_operation = :describe_endpoints
DescribeEndpointsRequest = Seahorse::Model::Shapes::StructureShape.new(
Expand Down