Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent data race in testing artifact fetcher #3685

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}
Loading