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]

Activity

  1. added
    bugThis issue is a bug.
    needs-triageThis issue or PR still needs to be triaged.
    on Jul 21, 2026
  2. jterapin commented on Jul 21, 2026

    @jterapin
    Contributor

    Hi! Thank you for reporting. We'll take a look and follow up if we have any questions.

  3. added
    investigatingIssue is being investigated
    in-progressWork is in progress to resolve the issue.
    and removed
    needs-triageThis issue or PR still needs to be triaged.
    investigatingIssue is being investigated
    on Jul 21, 2026
  4. jterapin commented on Jul 22, 2026

    @jterapin
    Contributor

    I've opened a PR with the fix, which is now under review by our team. Once it's approved and released, I'll follow up here with the aws-sdk-s3 version that includes it.

    Thanks again for the report and the suggested fix!

  5. github-actions commented on Jul 22, 2026

    @github-actions

    This issue is now closed. Comments on closed issues are hard for our team to see.
    If you need more assistance, please open a new issue that references this one.

  6. removed
    in-progressWork is in progress to resolve the issue.
    on Jul 24, 2026
  7. jterapin commented on Jul 24, 2026

    @jterapin
    Contributor

    Hi! Fix is released: https://rubygems.org/gems/aws-sdk-s3/versions/1.228.1

    Let me know if you have any questions. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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