Skip to content

Close source file on multipart upload_file part failure - #3409

Merged
jterapin merged 2 commits into
version-3from
file-part-fix
Jul 22, 2026
Merged

Close source file on multipart upload_file part failure#3409
jterapin merged 2 commits into
version-3from
file-part-fix

Conversation

@jterapin

Copy link
Copy Markdown
Contributor

Issue

Fixes #3408

Description

MultipartFileUploader closed each part's source file (p[:body].close) only on the success path, before the rescue/ensure. When a part upload raised, that line was skipped, so the failed part's FilePart was left open. FilePart opens the source lazily on first read and only releases it in #close, so every failed part leaked a file descriptor.

In long-running processes that retry failed uploads, this accumulates until file handles are exhausted. When the source is an unlinked temp file, the open descriptor also keeps its disk blocks allocated, so /tmp can fill (see the downstream report in mastodon/mastodon#39863).

Fix

Move p[:body].close into the ensure block so the file is released on both the success and error paths. FilePart#close is a no-op when the file was never opened and IO#close is idempotent, so there is no double-close concern.

Testing

Added a regression spec asserting every FilePart is closed when a part upload fails. It fails on main (the failed part is closed 0 times) and passes with this change. The existing specs and related uploader specs still pass.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jterapin
jterapin requested a review from a team as a code owner July 22, 2026 00:48
@jterapin
jterapin merged commit 096be81 into version-3 Jul 22, 2026
33 checks passed
@jterapin
jterapin deleted the file-part-fix branch July 22, 2026 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants