Repository navigation
Don't fail on two concurrent reference.store.AddDigest calls - #37781
Merged
Merged
Conversation
reference.store.addReference fails when adding a digest reference that already exists (regardless of the reference target). Both callers (via reference.store.AddDigest) do check in advance, using reference.store.Get, whether the digest reference exists before calling AddDigest, but the reference store lock is released between the two calls, so if another thread sets the reference in the meantime, AddDigest may fail with > Cannot overwrite digest ... . Handle this by checking that the pre-existing reference points at the same image, i.e. that there is nothing to do, and succeeding immediately in that case. This is even cheaper, avoids a reference.store.save() call. (In principle, the same failure could have happened via reference.store.AddTag, as > Conflict: Tag %s is already set to image %s, if you want to replace it, please use -f option but almost all callers (except for migrate/v1.Migrate, which is run single-threaded anyway) set the "force" parameter of AddTag to true, which makes the race invisible. This commit does not change the behavior of that case, except for speeding it up by avoiding the reference.store.save() call.) The existing reference.store.Get checks are now, in a sense, redundant as such, but their existence allows the callers to provide nice context-dependent error messages, so this commit leaves them unchanged. Signed-off-by: Miloslav Trmač <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #37781 +/- ##
=========================================
Coverage ? 35.86%
=========================================
Files ? 610
Lines ? 45547
Branches ? 0
=========================================
Hits ? 16336
Misses ? 26964
Partials ? 2247 |
nemacysts
added a commit
to Yelp/paasta
that referenced
this pull request
May 13, 2023
We've since upgraded the version of Docker we run and, according to moby/moby#37781 - this has now been fixed. Even without having found that PR, I'm pretty confident that this issue has been fixed as we pull an ungodly amount of simultaneous images in our kube nodes and have never seen issues like this :)
nemacysts
added a commit
to Yelp/paasta
that referenced
this pull request
May 15, 2023
We've since upgraded the version of Docker we run and, according to moby/moby#37781 - this has now been fixed. Even without having found that PR, I'm pretty confident that this issue has been fixed as we pull an ungodly amount of simultaneous images in our kube nodes and have never seen issues like this :)
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 I did
Fixed a race when two goroutines independently try to add the same digest reference.
- How I did it
See the commit message.
- How to verify it
On a trivial level, using the modified unit tests. Beyond that, whatever is the usual standard, I guess.
It should be in principle possible to make an actual reproducer by concurrently issuing many pull and/or push API requests for the same image (same manifest digest); I haven’t even attempted that so far. The race window is a few lines of Go code in an operation which involves remote HTTP requests, so it might require quite a few concurrent attempts.
I don’t have such a reproducer at this point; the race was found by code inspection based on a reported occurrence of the
Cannot overwrite digesterror message.- Description for the changelog
Fixes a race possibly causing one of several concurrent push/pull operations with the same remote image fail with “
Cannot overwrite digest …”.