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

Don't retry streaming requests with blocks after data has been recieved #1617

Merged
merged 7 commits into from Jun 11, 2020
1 change: 1 addition & 0 deletions gems/aws-sdk-core/lib/seahorse/client/block_io.rb
Expand Up @@ -11,6 +11,7 @@ def initialize(&block)
# @return [Integer]
def write(chunk)
@block.call(chunk)
ensure
chunk.bytesize.tap { |chunk_size| @size += chunk_size }
end

Expand Down
23 changes: 16 additions & 7 deletions gems/aws-sdk-core/lib/seahorse/client/plugins/response_target.rb
Expand Up @@ -28,7 +28,13 @@ def call(context)
def add_event_listeners(context, target)
handler = self
context.http_response.on_headers(200..299) do
context.http_response.body = handler.send(:io, target)
# In a fresh response body will be a StringIO
# However, when a request is retried we may have
# an existing ManagedFile or BlockIO and those
# should be reused.
if context.http_response.body.is_a? StringIO
context.http_response.body = handler.send(:io, target)
end
end

context.http_response.on_success(200..299) do
Expand All @@ -40,15 +46,18 @@ def add_event_listeners(context, target)

context.http_response.on_error do
body = context.http_response.body
File.unlink(body) if ManagedFile === body

# When using response_target of file we do not want to write
# error messages to the file. So set the body to a new StringIO
if body.is_a? ManagedFile
File.unlink(body)
context.http_response.body = StringIO.new
end

# Aws::S3::Encryption::DecryptHandler (with lower priority)
# has callbacks registered after ResponseTarget::Handler,
# where http_response.body is an IODecrypter
# and has error callbacks handling for it.
# Thus avoid early remove of IODecrypter at ResponseTarget::Handler
unless context.http_response.body.respond_to?(:io)
context.http_response.body = StringIO.new
end
# and has error callbacks handling for it so no action is required here
end
end

Expand Down
2 changes: 1 addition & 1 deletion gems/aws-sdk-personalize/CHANGELOG.md
Expand Up @@ -4,7 +4,7 @@ Unreleased Changes
1.13.0 (2020-06-05)
------------------

* Feature - [Personalize] Adds ability to create and apply filters.
* Feature - Adds ability to create and apply filters.

1.12.0 (2020-05-28)
------------------
Expand Down
2 changes: 1 addition & 1 deletion gems/aws-sdk-personalizeruntime/CHANGELOG.md
Expand Up @@ -4,7 +4,7 @@ Unreleased Changes
1.11.0 (2020-06-05)
------------------

* Feature - [Personalize] Adds ability to apply filter to real-time recommendations
* Feature - Adds ability to apply filter to real-time recommendations

1.10.0 (2020-05-28)
------------------
Expand Down
7 changes: 6 additions & 1 deletion gems/aws-sdk-s3/lib/aws-sdk-s3/encryption/io_decrypter.rb
Expand Up @@ -8,7 +8,8 @@ class IODecrypter
# @param [IO#write] io An IO-like object that responds to `#write`.
def initialize(cipher, io)
@cipher = cipher.clone
@io = io
# Ensure that IO is reset between retries
@io = io.tap { |io| io.truncate(0) if io.respond_to?(:truncate) }
end

# @return [#write]
Expand All @@ -23,6 +24,10 @@ def finalize
@io.write(@cipher.final)
end

def size
@io.size
end

end
end
end
Expand Down