Skip to content

Commit

Permalink
prevent data race in testing artifact fetcher (#3685) (#3695)
Browse files Browse the repository at this point in the history
(cherry picked from commit de1bda7)

Co-authored-by: Lee E Hinman <[email protected]>
  • Loading branch information
mergify[bot] and leehinman authored Nov 3, 2023
1 parent 6fb31d5 commit 3c8be72
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/testing/fetcher_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"path/filepath"
"strconv"
"strings"
"sync/atomic"
"time"
)

Expand Down Expand Up @@ -256,7 +257,7 @@ func DownloadPackage(ctx context.Context, l Logger, doer httpDoer, downloadPath
type writeProgress struct {
logger Logger
total uint64
completed uint64
completed atomic.Uint64
}

func newWriteProgress(ctx context.Context, l Logger, total uint64) *writeProgress {
Expand All @@ -270,7 +271,7 @@ func newWriteProgress(ctx context.Context, l Logger, total uint64) *writeProgres

func (wp *writeProgress) Write(p []byte) (int, error) {
n := len(p)
wp.completed += uint64(n)
wp.completed.Add(uint64(n))
return n, nil
}

Expand All @@ -282,7 +283,7 @@ func (wp *writeProgress) printProgress(ctx context.Context) {
case <-ctx.Done():
return
case <-t.C:
wp.logger.Logf("Downloading artifact progress %.2f%%", float64(wp.completed)/float64(wp.total)*100.0)
wp.logger.Logf("Downloading artifact progress %.2f%%", float64(wp.completed.Load())/float64(wp.total)*100.0)
}
}
}

0 comments on commit 3c8be72

Please sign in to comment.