magic-peach opened a new pull request, #70012: URL: https://github.com/apache/airflow/pull/70012
## Summary The `open_maybe_zipped` function (`airflow-core/src/airflow/utils/file.py:72`) creates a `ZipFile` object inline and calls `.open(filename)` on it: ```python return TextIOWrapper(zipfile.ZipFile(archive, mode=mode).open(filename)) ``` The `ZipFile` reference is lost after the return. The `TextIOWrapper` wraps the *inner* file object from `.open()`, but no one retains a reference to the outer `ZipFile`, so it can never be explicitly closed. The `ZipFile` (which holds an open file descriptor to the archive) will only be cleaned up when the garbage collector eventually runs, which is non-deterministic. Each call to this function with a zipped path leaks one file handle. **Fix**: Added a `_ZipFileWrapper` subclass of `TextIOWrapper` that closes both the inner file and the `ZipFile` when closed, ensuring proper cleanup of the archive file descriptor. --- ##### Was generative AI tooling used to co-author this PR? - [X] Yes — Claude Code (big-pickle) Generated-by: Claude Code (big-pickle) following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
