Skip to content
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

Bugfix: Don't close base images prematurely #455

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions distribution/pull_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,11 @@ func (p *v2Puller) pullSchema2Layers(ctx context.Context, target distribution.De
// Target image already exists locally, no need to pull anything
return digest, nil
}
deltaBase, err = DeltaBaseImageFromConfig(img.Config, p.config.ImageStore)
deltaBaseCloser, err := DeltaBaseImageFromConfig(img.Config, p.config.ImageStore)
if deltaBaseCloser != nil {
defer deltaBaseCloser.Close()
}
deltaBase = deltaBaseCloser
if err != nil {
return "", err
}
Expand Down Expand Up @@ -1029,6 +1033,8 @@ func toOCIPlatform(p manifestlist.PlatformSpec) specs.Platform {
// image associated with imgConfig. Passing an imgConfig that is not a delta
// image is not considered an error: in this case the function returns a nil
// ReadSeekCloser (and a nil error).
//
// The caller is responsible for Close()ing the returned stream.
func DeltaBaseImageFromConfig(imgConfig *container.Config, imgConfigStore ImageConfigStore) (ioutils.ReadSeekCloser, error) {
if base, ok := imgConfig.Labels["io.resin.delta.base"]; ok {
digest, err := digest.Parse(base)
Expand All @@ -1040,7 +1046,6 @@ func DeltaBaseImageFromConfig(imgConfig *container.Config, imgConfigStore ImageC
if err != nil {
return nil, fmt.Errorf("loading delta base image %q: %w", digest, err)
}
defer stream.Close()

return stream, nil
}
Expand Down
6 changes: 5 additions & 1 deletion image/tarexport/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool)
return nil
}

deltaBase, err = mobyDistribution.DeltaBaseImageFromConfig(img.Config, imgConfigStore)
deltaBaseCloser, err := mobyDistribution.DeltaBaseImageFromConfig(img.Config, imgConfigStore)
if deltaBaseCloser != nil {
defer deltaBaseCloser.Close()
}
deltaBase = deltaBaseCloser
if err != nil {
return err
}
Expand Down
Loading