Skip to content

Commit

Permalink
storage: use race-free AddNames instead of SetNames
Browse files Browse the repository at this point in the history
Commits from parallel builds using `SetNames` removes `names` from
storage for other builds.

Use race-free atomic `AddNames` to prevent breaking of parallel builds.

Signed-off-by: Aditya R <arajan@redhat.com>
  • Loading branch information
flouthoc committed Feb 24, 2022
1 parent 4508306 commit a939655
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions storage/storage_image.go
Expand Up @@ -1197,21 +1197,18 @@ func (s *storageImageDestination) Commit(ctx context.Context, unparsedToplevel t
}
logrus.Debugf("saved image metadata %q", string(metadata))
}
// Set the reference's name on the image. We don't need to worry about avoiding duplicate
// values because SetNames() will deduplicate the list that we pass to it.
if name := s.imageRef.DockerReference(); len(oldNames) > 0 || name != nil {
// Adds the reference's name on the image. We don't need to worry about avoiding duplicate
// values because AddNames() will deduplicate the list that we pass to it.
if name := s.imageRef.DockerReference(); name != nil {
names := []string{}
if name != nil {
names = append(names, name.String())
}
if len(oldNames) > 0 {
names = append(names, oldNames...)
if err := s.imageRef.transport.store.AddNames(img.ID, names); err != nil {
logrus.Debugf("error adding names %v on image %q: %v", names, img.ID, err)
return errors.Wrapf(err, "adding names %v on image %q", names, img.ID)
}
if err := s.imageRef.transport.store.SetNames(img.ID, names); err != nil {
logrus.Debugf("error setting names %v on image %q: %v", names, img.ID, err)
return errors.Wrapf(err, "setting names %v on image %q", names, img.ID)
}
logrus.Debugf("set names of image %q to %v", img.ID, names)
logrus.Debugf("add names of image %q to %v", img.ID, names)
}

commitSucceeded = true
Expand Down

0 comments on commit a939655

Please sign in to comment.