Skip to content

fix(verifier): single-flight OS image downloads and retry truncated bodies - #1205

Draft
Leechael wants to merge 1 commit into
release/0.6.0-rc3from
fix/verifier-image-download-singleflight
Draft

Leechael wants to merge 1 commit into
release/0.6.0-rc3from
fix/verifier-image-download-singleflight

Conversation

@Leechael

Copy link
Copy Markdown
Collaborator

Problem

Concurrent POST /verify for the same os_image_hash raced on the OS image cache. ensure_image_downloaded checked metadata.json with no lock, and download_image finished with exists() + remove_dir_all + rename on the shared destination. Under QUEUE_CONCURRENCY=20 that failed with Directory not empty (os error 39).

Truncated HTTP bodies also failed closed with no retry (end of file before message length reached).

Fix

Serialize same-hash downloads behind a per-hash async mutex and double-check metadata.json so only one task downloads. Retry truncated bodies up to 3 times, and reject a complete stream whose byte count does not match Content-Length.

Verified with cargo test -p dstack-verifier --all-features, including concurrent_same_hash_downloads_single_flight and truncated_image_download_retries_after_content_length_mismatch.

…odies

Same os_image_hash was downloaded by every concurrent /verify without a
lock. The finish path did exists()+remove_dir_all()+rename on the shared
cache directory, which fails with ENOTEMPTY (os error 39) under
QUEUE_CONCURRENCY=20.

Downloads also failed closed on truncated HTTP bodies
(end of file before message length reached) with no retry.

Serialize same-hash downloads behind a per-hash async mutex with
double-checked metadata.json, retry truncated bodies up to 3 times,
and reject a complete stream whose byte count does not match
Content-Length.
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