Skip to content

Conversation

@onuralpszr
Copy link
Member

@onuralpszr onuralpszr commented Jan 5, 2026

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Improves download safety by using uniquely named temp files to avoid collisions during concurrent downloads 🛡️⬇️

📊 Key Changes

  • Replaced a fixed temp filename (<dest>.part) with a unique temp filename format: <filename>.part.<pid>.<timestamp_nanos> 🧩
  • Builds the temp file name from the destination’s filename (or falls back to "download" if missing) 🗂️
  • Ensures the temp file is still created in the same directory as the final destination so the final rename remains atomic ⚙️
  • Keeps existing behavior of removing any pre-existing temp file at that unique path before starting 🧹

🎯 Purpose & Impact

  • Prevents race conditions and file clobbering when multiple processes/threads download the same asset at once (e.g., parallel inference workers) 🚦
  • Makes downloads more robust in shared environments (CI, servers, multi-user systems) 🏗️
  • Preserves atomic “download then rename” behavior, reducing the risk of partially downloaded files being mistaken for complete ones ✅

…s to prevent race conditions

Signed-off-by: Onuralp SEZER <[email protected]>
@onuralpszr onuralpszr changed the title fix: 🐞 Enhance atomic download by creating unique temporary file name… fix: 🐞 Enhance atomic download by creating unique temporary file names to prevent race conditions Jan 5, 2026
@UltralyticsAssistant UltralyticsAssistant added bug Something isn't working fixed Bug has been resolved labels Jan 5, 2026
@UltralyticsAssistant
Copy link
Member

👋 Hello @onuralpszr, thank you for submitting a ultralytics/inference 🚀 PR! This is an automated message—an Ultralytics engineer will review and assist soon. 🛠️

-✅ Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
-✅ Synchronize with Source: Confirm your PR is synchronized with the ultralytics/inference main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
-✅ Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
-✅ Update Documentation: Update the relevant documentation for any new or modified features.
-✅ Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
-✅ Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR by writing "I have read the CLA Document and I sign the CLA" in a new message.
-✅ Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

Copy link
Member

@UltralyticsAssistant UltralyticsAssistant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 PR Review

Made with ❤️ by Ultralytics Actions

Good direction: generating per-download temp filenames addresses the .part race while keeping temp files in the destination directory for atomic rename. The main issue is the uniqueness scheme: using only subsec_nanos() (and defaulting to 0 on time errors) can still collide and can hide clock problems. Tightening the suffix to include full time (or a stronger uniqueness source) would make this robust under high concurrency.

💬 Posted 2 inline comments

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@onuralpszr onuralpszr requested review from artest08 and removed request for artest08 January 5, 2026 10:03
@onuralpszr onuralpszr merged commit 84fb347 into main Jan 5, 2026
10 checks passed
@onuralpszr onuralpszr deleted the fix/download-model-test branch January 5, 2026 13:15
@UltralyticsAssistant
Copy link
Member

Merged! Huge thanks to @onuralpszr (with contributions from @fcakyon and @artest08) for strengthening download safety in Ultralytics Inference. Swapping the fixed .part temp name for a unique <filename>.part.<pid>.<timestamp_nanos> approach is a deceptively small change with outsized impact—eliminating collisions during concurrent downloads while preserving same-directory atomic renames.

“It is not the strongest of the species that survives, nor the most intelligent, but the one most responsive to change.” — Charles Darwin

This PR is exactly that kind of practical resilience: fewer race conditions, less chance of clobbered artifacts in CI/servers, and more reliable parallel inference workflows. Appreciate the care and craftsmanship—thank you all for helping make the stack more robust for everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fixed Bug has been resolved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants