1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #37781 from mtrmac/reference-race-upstream

Don't fail on two concurrent reference.store.AddDigest calls
This commit is contained in:
Yong Tang 2018-10-18 12:35:57 -07:00 committed by GitHub
commit f7e5154f37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View file

@ -149,6 +149,11 @@ func (store *store) addReference(ref reference.Named, id digest.Digest, force bo
oldID, exists := repository[refStr]
if exists {
if oldID == id {
// Nothing to do. The caller may have checked for this using store.Get in advance, but store.mu was unlocked in the meantime, so this can legitimately happen nevertheless.
return nil
}
// force only works for tags
if digested, isDigest := ref.(reference.Canonical); isDigest {
return errors.WithStack(conflictingTagError("Cannot overwrite digest " + digested.Digest().String()))

View file

@ -163,6 +163,10 @@ func TestAddDeleteGet(t *testing.T) {
if err = store.AddTag(ref4, testImageID2, false); err != nil {
t.Fatalf("error adding to store: %v", err)
}
// Write the same values again; should silently succeed
if err = store.AddTag(ref4, testImageID2, false); err != nil {
t.Fatalf("error redundantly adding to store: %v", err)
}
ref5, err := reference.ParseNormalizedNamed("username/repo3@sha256:58153dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c")
if err != nil {
@ -171,6 +175,10 @@ func TestAddDeleteGet(t *testing.T) {
if err = store.AddDigest(ref5.(reference.Canonical), testImageID2, false); err != nil {
t.Fatalf("error adding to store: %v", err)
}
// Write the same values again; should silently succeed
if err = store.AddDigest(ref5.(reference.Canonical), testImageID2, false); err != nil {
t.Fatalf("error redundantly adding to store: %v", err)
}
// Attempt to overwrite with force == false
if err = store.AddTag(ref4, testImageID3, false); err == nil || !strings.HasPrefix(err.Error(), "Conflict:") {