From 59484e8fef797603e7c93618e6b2c422eba64dfd Mon Sep 17 00:00:00 2001 From: Seth Hollandsworth Date: Wed, 13 Sep 2023 18:48:50 -0400 Subject: [PATCH 1/2] defaulting to unbuffered reader for dmverity hashing (#1887) Signed-off-by: Seth Hollandsworth Co-authored-by: ksayid (cherry picked from commit e7509cc6636d89ad8e748bb4c127f83af7131b05) Signed-off-by: Maksim An --- cmd/dmverity-vhd/main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/dmverity-vhd/main.go b/cmd/dmverity-vhd/main.go index 439a750352..0add4a2189 100644 --- a/cmd/dmverity-vhd/main.go +++ b/cmd/dmverity-vhd/main.go @@ -103,7 +103,13 @@ func fetchImageLayers(ctx *cli.Context) (layers []v1.Layer, err error) { // if only an image name is provided and not a tag, the default is "latest" img, err = tarball.ImageFromPath(tarballPath, &imageNameAndTag) } else if dockerDaemon { - img, err = daemon.Image(ref) + // use the unbuffered opener, the tradeoff being the image will stream as needed + // so it is slower but much more memory efficient + var opts []daemon.Option + opt := daemon.WithUnbufferedOpener() + opts = append(opts, opt) + + img, err = daemon.Image(ref, opts...) } else { var remoteOpts []remote.Option if ctx.IsSet(usernameFlag) && ctx.IsSet(passwordFlag) { From ca836f4757a7d1697d140592dcfceaf84a510ced Mon Sep 17 00:00:00 2001 From: Djordje Lukic Date: Thu, 14 Sep 2023 19:50:59 +0200 Subject: [PATCH 2/2] Fix closing stdin (#1899) Send the modify request even if stdin is nil, let the process handle it Signed-off-by: Djordje Lukic (cherry picked from commit 27df1b95b69faaeca97de86d25d68f48f89bc0b9) Signed-off-by: Maksim An --- internal/hcs/process.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/hcs/process.go b/internal/hcs/process.go index e437e297c0..65025f3f9b 100644 --- a/internal/hcs/process.go +++ b/internal/hcs/process.go @@ -421,12 +421,6 @@ func (process *Process) CloseStdin(ctx context.Context) (err error) { return makeProcessError(process, operation, ErrAlreadyClosed, nil) } - process.stdioLock.Lock() - defer process.stdioLock.Unlock() - if process.stdin == nil { - return nil - } - //HcsModifyProcess request to close stdin will fail if the process has already exited if !process.stopped() { modifyRequest := processModifyRequest{ @@ -448,8 +442,12 @@ func (process *Process) CloseStdin(ctx context.Context) (err error) { } } - process.stdin.Close() - process.stdin = nil + process.stdioLock.Lock() + defer process.stdioLock.Unlock() + if process.stdin != nil { + process.stdin.Close() + process.stdin = nil + } return nil }