Skip to content

Close FTP file handles when a transfer raises - #69083

Merged
dabla merged 1 commit into
apache:mainfrom
itej13:fix-ftp-file-handle-leak
Jun 28, 2026
Merged

Close FTP file handles when a transfer raises#69083
dabla merged 1 commit into
apache:mainfrom
itej13:fix-ftp-file-handle-leak

Conversation

@itej13

@itej13 itej13 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

FTPHook.retrieve_file and FTPHook.store_file opened a local file and then ran the FTP transfer before calling close(). If the transfer raised — a routine occurrence for network I/O — the handle was never closed and leaked for the lifetime of the process.

Wrapping the transfer in try/finally guarantees the handle we opened is always closed, while still leaving a caller-supplied file-like buffer open (the method's existing contract). Adds regression tests for both methods that fail without the fix.

closes: #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

retrieve_file and store_file opened a local file, then ran the FTP
transfer before calling close(). When the transfer raised, the handle
was never closed and leaked for the lifetime of the process. Wrapping
the transfer in try/finally guarantees the handle we opened is closed
on every path, while still leaving caller-supplied buffers open.

closes: apache#69077
@boring-cyborg

boring-cyborg Bot commented Jun 27, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@eladkal
eladkal requested review from dabla and shahar1 June 27, 2026 15:54
@dabla
dabla merged commit 5d56b99 into apache:main Jun 28, 2026
77 checks passed
@boring-cyborg

boring-cyborg Bot commented Jun 28, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

karenbraganz pushed a commit to karenbraganz/airflow that referenced this pull request Jun 30, 2026
retrieve_file and store_file opened a local file, then ran the FTP
transfer before calling close(). When the transfer raised, the handle
was never closed and leaked for the lifetime of the process. Wrapping
the transfer in try/finally guarantees the handle we opened is closed
on every path, while still leaving caller-supplied buffers open.

closes: apache#69077
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential resource leak when exception occurs during file operation

4 participants