Skip to content

Close S3 download_file handle after download or failure#69084

Merged
shahar1 merged 1 commit into
apache:mainfrom
itej13:fix-s3-download-file-handle-leak
Jun 28, 2026
Merged

Close S3 download_file handle after download or failure#69084
shahar1 merged 1 commit into
apache:mainfrom
itej13:fix-s3-download-file-handle-leak

Conversation

@itej13

@itej13 itej13 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

S3Hook.download_file opened a local file (or a NamedTemporaryFile with delete=False), streamed the object into it, and returned the path without ever closing the handle — relying on garbage collection to release the descriptor. On a download error the handle leaked the same way.

Closing it in a finally releases the descriptor on every path (success and failure) while keeping the downloaded file on disk for the caller. Adds a regression test asserting the handle is closed when the download raises.

related: #69077


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.8)

Generated-by: Claude Code (Opus 4.8) following the guidelines

S3Hook.download_file opened a local file (or NamedTemporaryFile with
delete=False), streamed the object into it, and returned the path
without ever closing the handle, relying on garbage collection to
release the descriptor. On a download error the handle leaked the same
way. Closing it in a finally releases the descriptor on every path while
keeping the downloaded file on disk for the caller.
@itej13 itej13 requested a review from o-nikolas as a code owner June 27, 2026 12:01
@boring-cyborg boring-cyborg Bot added area:providers provider:amazon AWS/Amazon - related issues labels Jun 27, 2026
@shahar1 shahar1 merged commit fe8e5df into apache:main Jun 28, 2026
81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:amazon AWS/Amazon - related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants