fix: prevent duplicate model downloads with atomic check-and-set#578
Open
ianliuy wants to merge 1 commit intoome-projects:mainfrom
Open
fix: prevent duplicate model downloads with atomic check-and-set#578ianliuy wants to merge 1 commit intoome-projects:mainfrom
ianliuy wants to merge 1 commit intoome-projects:mainfrom
Conversation
Move the activeDownloads check and registration into the same mutex-locked critical section in processTask(). Previously, two download workers could both pass the check before either registered, causing duplicate downloads of the same model. The fix performs an atomic check-and-set: lock the mutex, check if the model is already downloading, and if not, register the cancel function before releasing the lock. If another worker is already downloading the model, the duplicate task is skipped with an info log. Fixes ome-projects#308 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Yiyang Liu <37043548+ianliuy@users.noreply.github.com>
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
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.
What's broken?
When a new
ClusterBaseModelis created with--num-download-worker=2or more, two download workers both start downloading the same model simultaneously. This duplicates all model shards and can produce a corruptedconfig.jsonfrom concatenated writes.Who is affected?
Any OME deployment with multiple download workers (
--num-download-worker>=2). Single-worker deployments are unaffected.When does it trigger?
When a
DownloadandDownloadOverridetask for the same model are processed within milliseconds of each other — both workers enterprocessTask()before either registers inactiveDownloads.Where is the bug?
pkg/modelagent/gopher.go, lines 278-284 (before this fix). The context creation andactiveDownloadsregistration were separate from any existence check:Why does it happen?
The check-then-act on
activeDownloadswas not atomic. Worker 1 could create its context and be about to lock the mutex, while Worker 2 also creates its context — neither has registered yet, so neither sees the other.How did we fix it?
Atomic check-and-set inside the mutex: lock → check if model is already downloading → if not, create context and register → unlock. If another worker is already downloading the model, the duplicate task returns early with an info log.
This is the minimal fix — 1 file, 12 insertions / 8 deletions. The existing
defercleanup andDeletetask cancellation logic are unchanged.How do we know it works?
The fix ensures the TOCTOU window is eliminated: no two workers can both pass the "not downloading" check for the same model, because the check and registration happen inside the same lock acquisition.
Fixes #308