diff --git a/cmd/skopeo/proxy.go b/cmd/skopeo/proxy.go index ee46f47f..d3423638 100644 --- a/cmd/skopeo/proxy.go +++ b/cmd/skopeo/proxy.go @@ -75,12 +75,14 @@ import ( "github.com/containers/image/v5/manifest" ocilayout "github.com/containers/image/v5/oci/layout" "github.com/containers/image/v5/pkg/blobinfocache" + "github.com/containers/image/v5/transports" "github.com/containers/image/v5/transports/alltransports" "github.com/containers/image/v5/types" dockerdistributionerrcode "github.com/docker/distribution/registry/api/errcode" dockerdistributionapi "github.com/docker/distribution/registry/api/v2" "github.com/opencontainers/go-digest" imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -701,6 +703,17 @@ func (h *proxyHandler) FinishPipe(args []interface{}) (replyBuf, error) { return ret, err } +// close releases all resources associated with this proxy backend +func (h *proxyHandler) close() { + for _, image := range h.images { + err := image.src.Close() + if err != nil { + // This shouldn't be fatal + logrus.Warnf("Failed to close image %s: %v", transports.ImageName(image.cachedimg.Reference()), err) + } + } +} + // send writes a reply buffer to the socket func (buf replyBuf) send(conn *net.UnixConn, err error) error { replyToSerialize := reply{ @@ -816,6 +829,7 @@ func (opts *proxyOptions) run(args []string, stdout io.Writer) error { images: make(map[uint32]*openImage), activePipes: make(map[uint32]*activePipe), } + defer handler.close() // Convert the socket FD passed by client into a net.FileConn fd := os.NewFile(uintptr(opts.sockFd), "sock")