Skip to content

fix: close files upload resources on every exit - #1150

Open
Linxiushen wants to merge 1 commit into
volcengine:mainfrom
Linxiushen:fix/files-upload-resource-cleanup
Open

Linxiushen wants to merge 1 commit into
volcengine:mainfrom
Linxiushen:fix/files-upload-resource-cleanup

Conversation

@Linxiushen

Copy link
Copy Markdown

upload_to_files_api creates an AsyncArk client 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:

  • Seven regression cases fail on unchanged 763865db9fb3b643e9fc0f04e2e0790ea5a4fc65 because the owned SDK client remains open. All seven pass with the fix.
  • Tests execute the real AsyncArk SDK, multipart upload and polling code, real HTTPX client and real file handles. HTTP responses use httpx.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.

This branch has not been deployed

No deployments
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.

1 participant