Skip to content

Aws::S3::MultipartFileUploader leaks file descriptors on error #3408

Description

@ClearlyClaire

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

  • Select this option if this issue appears to be a regression.

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions