Skip to content

Commit

Permalink
Merge pull request #455 from balena-os/lmb/bugfix-delta-stream-closing
Browse files Browse the repository at this point in the history
Bugfix: Don't close base images prematurely
  • Loading branch information
alexgg authored May 21, 2024
2 parents c10820d + 01a3fc3 commit 56a9b7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit 56a9b7f

Please sign in to comment.