mirror of
https://github.com/containers/skopeo.git
synced 2025-07-01 00:52:26 +00:00
proxy: Ensure images are closed when proxy is shutting down
This is a complementary fix for https://github.com/coreos/rpm-ostree/issues/4213 Basically in the case of `oci-archive` we have a temporary directory that needs cleanup. Signed-off-by: Colin Walters <walters@verbum.org> Co-authored-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Colin Walters <walters@verbum.org>
This commit is contained in:
parent
e024c43892
commit
b51f8ea200
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user