From 7839e114c3b7d2b49e67f2e720efc4317a160a6a Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Wed, 1 Mar 2023 13:41:55 -0500 Subject: [PATCH 1/2] fix: thread safety for progress Signed-off-by: Keith Zantow --- go.mod | 2 ++ pkg/image/docker/pull_status.go | 10 +++++----- pkg/image/image.go | 10 +++++----- pkg/image/layer.go | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index e50a4d1c..79dd425d 100644 --- a/go.mod +++ b/go.mod @@ -84,3 +84,5 @@ require ( google.golang.org/protobuf v1.28.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/wagoodman/go-progress => ../go-progress diff --git a/pkg/image/docker/pull_status.go b/pkg/image/docker/pull_status.go index 76272ec9..34a889b4 100644 --- a/pkg/image/docker/pull_status.go +++ b/pkg/image/docker/pull_status.go @@ -122,17 +122,17 @@ func (p *PullStatus) onEvent(event *pullEvent) { if currentPhase >= AlreadyExistsPhase { phaseProgress.SetCompleted() } else { - phaseProgress.N = int64(event.ProgressDetail.Current) - phaseProgress.Total = int64(event.ProgressDetail.Total) + phaseProgress.Set(int64(event.ProgressDetail.Current)) + phaseProgress.SetTotal(int64(event.ProgressDetail.Total)) } if currentPhase == DownloadingPhase { dl := p.downloadProgress[layer] - dl.N = int64(event.ProgressDetail.Current) - dl.Total = int64(event.ProgressDetail.Total) + dl.Set(int64(event.ProgressDetail.Current)) + dl.SetTotal(int64(event.ProgressDetail.Total)) } else if currentPhase >= DownloadCompletePhase { dl := p.downloadProgress[layer] - dl.N = dl.Total + dl.Set(dl.Size()) dl.SetCompleted() } } diff --git a/pkg/image/image.go b/pkg/image/image.go index 9798197b..b8a34b5c 100644 --- a/pkg/image/image.go +++ b/pkg/image/image.go @@ -155,10 +155,10 @@ func (i *Image) IDs() []string { } func (i *Image) trackReadProgress(metadata Metadata) *progress.Manual { - prog := &progress.Manual{ + prog := progress.NewManual( // x2 for read and squash of each layer - Total: int64(len(metadata.Config.RootFS.DiffIDs) * 2), - } + int64(len(metadata.Config.RootFS.DiffIDs) * 2), + ) bus.Publish(partybus.Event{ Type: event.ReadImage, @@ -217,7 +217,7 @@ func (i *Image) Read() error { i.Metadata.Size += layer.Metadata.Size layers = append(layers, layer) - readProg.N++ + readProg.Increment() } i.Layers = layers @@ -257,7 +257,7 @@ func (i *Image) squash(prog *progress.Manual) error { layer.SquashedSearchContext = filetree.NewSearchContext(layer.SquashedTree, layer.fileCatalog.Index) lastSquashTree = squashedTree - prog.N++ + prog.Increment() } prog.SetCompleted() diff --git a/pkg/image/layer.go b/pkg/image/layer.go index f0b1267d..df202cd4 100644 --- a/pkg/image/layer.go +++ b/pkg/image/layer.go @@ -240,7 +240,7 @@ func layerTarIndexer(ft filetree.Writer, fileCatalog *FileCatalog, size *int64, fileCatalog.addImageReferences(ref.ID(), layerRef, index.Open) if monitor != nil { - monitor.N++ + monitor.Increment() } return nil } @@ -285,7 +285,7 @@ func squashfsVisitor(ft filetree.Writer, fileCatalog *FileCatalog, size *int64, return r }) - monitor.N++ + monitor.Increment() return nil } } From 3edecbf03d7674b2d79794e604de384f61501ebd Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Wed, 1 Mar 2023 14:09:22 -0500 Subject: [PATCH 2/2] chore: update go-progress version Signed-off-by: Keith Zantow --- go.mod | 4 +--- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 79dd425d..03fd095a 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/sylabs/sif/v2 v2.8.1 github.com/sylabs/squashfs v0.6.1 github.com/wagoodman/go-partybus v0.0.0-20200526224238-eb215533f07d - github.com/wagoodman/go-progress v0.0.0-20200621122631-1a2120f0695a + github.com/wagoodman/go-progress v0.0.0-20230301185719-21920a456ad5 golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd ) @@ -84,5 +84,3 @@ require ( google.golang.org/protobuf v1.28.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -replace github.com/wagoodman/go-progress => ../go-progress diff --git a/go.sum b/go.sum index fbbc8b4a..562cb7ce 100644 --- a/go.sum +++ b/go.sum @@ -800,8 +800,8 @@ github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17 github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/wagoodman/go-partybus v0.0.0-20200526224238-eb215533f07d h1:KOxOL6qpmqwoPloNwi+CEgc1ayjHNOFNrvoOmeDOjDg= github.com/wagoodman/go-partybus v0.0.0-20200526224238-eb215533f07d/go.mod h1:JPirS5jde/CF5qIjcK4WX+eQmKXdPc6vcZkJ/P0hfPw= -github.com/wagoodman/go-progress v0.0.0-20200621122631-1a2120f0695a h1:lV3ioFpbqvfZ1bXSQfloLWzom1OPU/5UjyU0wmBlkNc= -github.com/wagoodman/go-progress v0.0.0-20200621122631-1a2120f0695a/go.mod h1:jLXFoL31zFaHKAAyZUh+sxiTDFe1L1ZHrcK2T1itVKA= +github.com/wagoodman/go-progress v0.0.0-20230301185719-21920a456ad5 h1:lwgTsTy18nYqASnH58qyfRW/ldj7Gt2zzBvgYPzdA4s= +github.com/wagoodman/go-progress v0.0.0-20230301185719-21920a456ad5/go.mod h1:jLXFoL31zFaHKAAyZUh+sxiTDFe1L1ZHrcK2T1itVKA= github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=