Describe the bug
After investigating an issue that was reported out against our project (mastodon/mastodon#39863), I am under the impression that multipart file uploads as currently implemented in aws-sdk-s3 are leaking file descriptors when hitting upload errors.
Regression Issue
Expected Behavior
MultipartFileUploader always closes files it opens.
Current Behavior
MultipartFileUploader seems to only close opened file descriptors for part uploads on success.
Reproduction Steps
Upload a file using Multipart File Upload with very low timeouts so that uploading fails and leaks file descriptors.
Possible Solution
p[:body].close should probably be called in the ensure or rescue block (see monkey-patch that seems to solve the issue: mastodon/mastodon#39863 (comment))
Additional Information/Context
|
@executor.post(part) do |p| |
|
Thread.current[:net_http_override_body_stream_chunk] = @http_chunk_size if @http_chunk_size |
|
update_progress(progress, p) |
|
resp = @client.upload_part(p) |
|
p[:body].close |
|
completed_part = { etag: resp.etag, part_number: p[:part_number] } |
|
apply_part_checksum(resp, completed_part) |
|
completed.push(completed_part) |
|
rescue StandardError => e |
|
abort_upload = true |
|
errors << e |
|
ensure |
|
Thread.current[:net_http_override_body_stream_chunk] = nil if @http_chunk_size |
|
completion_queue << :done |
|
end |
Gem name ('aws-sdk', 'aws-sdk-resources' or service gems like 'aws-sdk-s3') and its version
aws-sdk-s3 1.225.1
Environment details (Version of Ruby, OS environment)
ruby 4.0.5 (2026-05-20 revision 64336ffd0e) +PRISM [x86_64-linux]
Describe the bug
After investigating an issue that was reported out against our project (mastodon/mastodon#39863), I am under the impression that multipart file uploads as currently implemented in
aws-sdk-s3are leaking file descriptors when hitting upload errors.Regression Issue
Expected Behavior
MultipartFileUploaderalways closes files it opens.Current Behavior
MultipartFileUploaderseems to only close opened file descriptors for part uploads on success.Reproduction Steps
Upload a file using Multipart File Upload with very low timeouts so that uploading fails and leaks file descriptors.
Possible Solution
p[:body].closeshould probably be called in theensureorrescueblock (see monkey-patch that seems to solve the issue: mastodon/mastodon#39863 (comment))Additional Information/Context
aws-sdk-ruby/gems/aws-sdk-s3/lib/aws-sdk-s3/multipart_file_uploader.rb
Lines 153 to 167 in 53d6f17
Gem name ('aws-sdk', 'aws-sdk-resources' or service gems like 'aws-sdk-s3') and its version
aws-sdk-s3 1.225.1
Environment details (Version of Ruby, OS environment)
ruby 4.0.5 (2026-05-20 revision 64336ffd0e) +PRISM [x86_64-linux]