Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions common/pkg/libartifact/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,8 @@ func (as ArtifactStore) Add(ctx context.Context, dest string, artifactBlobs []li
return nil, errors.New("append option is not compatible with type option")
}

locked := true
as.lock.Lock()
defer func() {
if locked {
as.lock.Unlock()
}
}()
defer as.lock.Unlock()

// Check if artifact already exists
artifacts, err := as.getArtifacts(ctx, nil)
Expand Down Expand Up @@ -297,10 +292,11 @@ func (as ArtifactStore) Add(ctx context.Context, dest string, artifactBlobs []li
}
defer imageDest.Close()

// Unlock around the actual pull of the blobs.
// This is ugly as hell, but should be safe.
locked = false
as.lock.Unlock()
// Keep the lock held during blob copying to prevent concurrent artifact adds
// from racing on the OCI layout index file. The lock was previously released
// here as an optimization, but this created a race condition where concurrent
// artifact additions could overwrite each other's index entries.
// See: https://github.com/containers/podman/issues/27569

// ImageDestination, in general, requires the caller to write a full image; here we may write only the added layers.
// This works for the oci/layout transport we hard-code.
Expand Down Expand Up @@ -356,8 +352,7 @@ func (as ArtifactStore) Add(ctx context.Context, dest string, artifactBlobs []li
artifactManifest.Layers = append(artifactManifest.Layers, newLayer)
}

as.lock.Lock()
locked = true
// Lock is still held from the beginning of the function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment does not make much sense stand-alone for future readers of the code, without seeing it in this diff.


rawData, err := json.Marshal(artifactManifest)
if err != nil {
Expand Down
Loading