summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin@redhat.com>2021-03-15 12:03:22 -0400
committerNalin Dahyabhai <nalin@redhat.com>2021-03-16 14:14:32 -0400
commite8918ff10bafcdba7397c257fe5402a820698ee9 (patch)
tree743421febc436cec50c0c6d9c80a561b4060507a
parent604459b404ed190f51e8b368c619323317078232 (diff)
downloadpodman-e8918ff10bafcdba7397c257fe5402a820698ee9.tar.gz
podman-e8918ff10bafcdba7397c257fe5402a820698ee9.tar.bz2
podman-e8918ff10bafcdba7397c257fe5402a820698ee9.zip
pkg/bindings/images.Build(): fix a race condition in error reporting
In nTar(), don't return the error value when the goroutine that's populating the error value can continue running long after nTar() returns. Instead, wrap the Close() method of the pipe that we're returning in a function that collects those errors, along with any error we get from closing the pipe, and returns them from Close() wrapper. In Build(), if the Close() method returns an error, at least log it. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
-rw-r--r--pkg/bindings/images/build.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go
index 1cbd28c37..9d77883f9 100644
--- a/pkg/bindings/images/build.go
+++ b/pkg/bindings/images/build.go
@@ -20,6 +20,7 @@ import (
"github.com/containers/podman/v3/pkg/bindings"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/storage/pkg/fileutils"
+ "github.com/containers/storage/pkg/ioutils"
"github.com/docker/go-units"
"github.com/hashicorp/go-multierror"
jsoniter "github.com/json-iterator/go"
@@ -252,7 +253,11 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
logrus.Errorf("cannot tar container entries %v error: %v", entries, err)
return nil, err
}
- defer tarfile.Close()
+ defer func() {
+ if err := tarfile.Close(); err != nil {
+ logrus.Errorf("%v\n", err)
+ }
+ }()
containerFile, err := filepath.Abs(entries[0])
if err != nil {
@@ -340,7 +345,7 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
gw := gzip.NewWriter(pw)
tw := tar.NewWriter(gw)
- var merr error
+ var merr *multierror.Error
go func() {
defer pw.Close()
defer gw.Close()
@@ -421,7 +426,14 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
merr = multierror.Append(merr, err)
}
}()
- return pr, merr
+ rc := ioutils.NewReadCloserWrapper(pr, func() error {
+ if merr != nil {
+ merr = multierror.Append(merr, pr.Close())
+ return merr.ErrorOrNil()
+ }
+ return pr.Close()
+ })
+ return rc, nil
}
func parseDockerignore(root string) ([]string, error) {