aws/aws-sdk-ruby

Errors downloading files from s3 are propagated to incorrect thread

DanielHeath opened this issue · 8 comments

Describe the bug

While downloading files from S3, any exceptions are propagated to the main thread instead of the calling thread.

This appears to be due to the use of Thread.abort_on_exception (see

thread.abort_on_exception = true
).

Expected Behavior

Exceptions propagate to the calling context

Current Behavior

Exceptions are propagated to the main thread, interrupting unrelated code.

Reproduction Steps

workers = []
workers << Thread.new do
  begin
    Aws::S3::Object.new(bucket_name: "test", key: "fails_to_download").download_file("outputfile")
  rescue
    puts "We should get here if the download failed, but do not."
  end
end
workers.each &:join

puts "We should get here regardless of the download failing or succeeding, but do not"

Because the error is propagated to the main thread instead of the calling thread, and the main thread has no exception handler, the process aborts unexpectedly.

Possible Solution

Instead of using abort_on_exception, store the calling thread at the start of download_in_threads and use calling_thread.raise(exception) to propagate errors.

Additional Information/Context

No response

Gem name ('aws-sdk', 'aws-sdk-resources' or service gems like 'aws-sdk-s3') and its version

aws-sdk-s3

Environment details (Version of Ruby, OS environment)

3.2.2 / linux

Thanks for reporting this, we will be taking a look.

Hi! Which version are you using for the aws-sdk-s3? Is it the latest, which is 1.137.0?

aws-sdk-s3 (1.136.0) - will update and confirm it affects 137

Yep, still an issue.

Instead of using abort_on_exception, store the calling thread at the start of download_in_threads and use calling_thread.raise(exception) to propagate errors.

Is removing abort_on_exception sufficient here? Thread's value method will raise the exception that terminated the thread, presumably bubbling up to the calling thread automatically.

Ahh that's a good point - simply removing abort_on_exception does appear to fix it.

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Thank you for your patience! The fix has been merged into main but a new version of S3 gem will not be released until around Dec 4 (due to reInvent). Apologizes for the inconvenience.