Repository navigation
fix: close files upload resources on every exit - #1150
Open
Linxiushen wants to merge 1 commit into
Open
Linxiushen wants to merge 1 commit into
Linxiushen wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
upload_to_files_apicreates anAsyncArkclient and opens a local file without explicitly closing either. Successful uploads, upload/poll failures, processing timeouts and cancellation can therefore leave cleanup to object finalization instead of completing it before the helper returns or raises.Use the SDK's async context manager for the whole operation and a file context manager for the upload only. The local file is closed before polling begins; the owned HTTP client closes on every exit, including a missing local file. Upload arguments, polling settings, return value and exception propagation are unchanged.
Validation:
763865db9fb3b643e9fc0f04e2e0790ea5a4fc65because the owned SDK client remains open. All seven pass with the fix.AsyncArkSDK, multipart upload and polling code, real HTTPX client and real file handles. HTTP responses usehttpx.MockTransport; a configuration double isolates credential discovery. Cases cover success, upload/poll HTTP errors, processing timeout, cancellation during upload/polling, and a missing file. The tests also verify the file is closed before polling.python -m pytest tests/utils/test_files_upload_cleanup.py -q --tb=short: 7 passed on Windows/Python 3.12.13, Ark SDK 5.0.50 and HTTPX 0.28.1.python -m pre_commit run --all-files --show-diff-on-failure: Ruff check, Ruff format and gitleaks pass.No live Ark request or credential-dependent/full project suite was run. Developed with AI assistance and independently reviewed by a second agent; no human testing is claimed.