Skip to content

Commit

Permalink
Deleting waitgroup from concurrencyTools (#2244)
Browse files Browse the repository at this point in the history
## Description

Wait group was unnecessary in concurrencyTools, we are deleting it

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [X] Other (security config, docs update, etc)

## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
- [ ] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed
  • Loading branch information
AustinAbro321 authored Jan 23, 2024
1 parent f039aff commit b46898a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 20 deletions.
6 changes: 0 additions & 6 deletions src/internal/packager/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ func (i *ImageConfig) PullAll() ([]ImgInfo, error) {
// Create a closure so that we can pass the src into the goroutine
refInfo := refInfo
go func() {
// Make sure to call Done() on the WaitGroup when the goroutine finishes
defer metadataImageConcurrency.WaitGroupDone()

if metadataImageConcurrency.IsDone() {
return
Expand Down Expand Up @@ -202,7 +200,6 @@ func (i *ImageConfig) PullAll() ([]ImgInfo, error) {
// and https://github.com/google/go-containerregistry/blob/v0.15.2/pkg/v1/layout/write.go#L198-L262
// with modifications. This allows us to dedupe layers for all images and write them concurrently.
go func() {
defer layerWritingConcurrency.WaitGroupDone()
digest, err := layer.Digest()
if errors.Is(err, stream.ErrNotComputed) {
// Allow digest errors, since streams may not have calculated the hash
Expand Down Expand Up @@ -347,9 +344,6 @@ func (i *ImageConfig) PullAll() ([]ImgInfo, error) {
// Create a closure so that we can pass the refInfo and img into the goroutine
refInfo, img := refInfo, img
go func() {
// Make sure to call Done() on the WaitGroup when the goroutine finishes
defer imageSavingConcurrency.WaitGroupDone()

// Save the image via crane
err := cranePath.WriteImage(img)

Expand Down
14 changes: 0 additions & 14 deletions src/pkg/utils/concurrency.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package utils

import (
"context"
"sync"
)

// ConcurrencyTools is a struct that contains channels and a context for use in concurrent routines
Expand All @@ -16,7 +15,6 @@ type ConcurrencyTools[P any, E any] struct {
ErrorChan chan E
context context.Context
Cancel context.CancelFunc
waitGroup *sync.WaitGroup
routineCount int
}

Expand All @@ -30,16 +28,11 @@ func NewConcurrencyTools[P any, E any](length int) *ConcurrencyTools[P, E] {

errorChan := make(chan E, length)

waitGroup := sync.WaitGroup{}

waitGroup.Add(length)

concurrencyTools := ConcurrencyTools[P, E]{
ProgressChan: progressChan,
ErrorChan: errorChan,
context: ctx,
Cancel: cancel,
waitGroup: &waitGroup,
routineCount: length,
}

Expand All @@ -57,11 +50,6 @@ func (ct *ConcurrencyTools[P, E]) IsDone() bool {
}
}

// WaitGroupDone decrements the internal WaitGroup counter by one.
func (ct *ConcurrencyTools[P, E]) WaitGroupDone() {
ct.waitGroup.Done()
}

// WaitWithProgress waits for all routines to finish
//
// onProgress is a callback function that is called when a routine sends a progress update
Expand All @@ -78,7 +66,6 @@ func (ct *ConcurrencyTools[P, E]) WaitWithProgress(onProgress func(P, int), onEr
onProgress(progress, i)
}
}
ct.waitGroup.Wait()
return nil
}

Expand All @@ -95,6 +82,5 @@ func (ct *ConcurrencyTools[P, E]) WaitWithoutProgress(onError func(E) error) err
case <-ct.ProgressChan:
}
}
ct.waitGroup.Wait()
return nil
}

0 comments on commit b46898a

Please sign in to comment.