-
Notifications
You must be signed in to change notification settings - Fork 97
fix: acquire read lock for r.blobs in test registry POST handler #678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,9 @@ func (r *Registry) handleBlobUpload(w http.ResponseWriter, req *http.Request, pa | |
| switch req.Method { | ||
| case http.MethodPost: | ||
| // Start upload | ||
| r.mu.RLock() | ||
| uploadID := fmt.Sprintf("upload-%d", len(r.blobs)) | ||
| r.mu.RUnlock() | ||
|
Comment on lines
+72
to
+74
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the |
||
| location := fmt.Sprintf("/v2/%s/blobs/uploads/%s", repo, uploadID) | ||
| w.Header().Set("Location", location) | ||
| w.Header().Set("Docker-Upload-UUID", uploadID) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Using RLock here still allows concurrent readers to generate duplicate upload IDs based on len(r.blobs).
Because
RLockallows concurrent readers, multiple goroutines can observe the samelen(r.blobs)and generate identicaluploadIDs. To ensure uniqueness, this section should either use the exclusive mutex (mu.Lock/mu.Unlock) around ID generation, or switch to a different mechanism (e.g., atomic counter or UUID). As is, the map access is safe but the ID generation still has a race condition.