fix(pb): make disableProgress race-free with sync/atomic.Bool#511
Merged
chlins merged 1 commit intomodelpack:mainfrom Apr 21, 2026
Merged
fix(pb): make disableProgress race-free with sync/atomic.Bool#511chlins merged 1 commit intomodelpack:mainfrom
chlins merged 1 commit intomodelpack:mainfrom
Conversation
internal/pb package used an unprotected package-level `disableProgress` bool that's read by `(*ProgressBar).Add` from the concurrent pull/push worker goroutines while `SetDisableProgress` flips it on startup. `go test -race` reports the expected data race, and the Go memory model leaves the behaviour undefined in practice. Swap the bool for an atomic.Bool. Store from SetDisableProgress, Load from Add. No public-API change - callers continue to pass plain bool to SetDisableProgress. Fixes modelpack#493 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request converts the disableProgress flag to an atomic.Bool to ensure thread-safe access across concurrent goroutines, specifically for pull/push workers. It updates the SetDisableProgress and Add methods to use atomic operations. I have no feedback to provide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
internal/pb/pb.go:33-40declares a package-leveldisableProgressbool that gets written bySetDisableProgress(disable bool)and read from the progress-bar hot path inside(*ProgressBar).Add:Multiple concurrent pull/push workers call
Addfrom their goroutines while the main goroutine (CLI arg parsing, feature flags, etc.) may still flipdisableProgress. The access is unsynchronised, so per #493go test -racereports a data race, and the Go memory model leaves the behaviour undefined in practice.Fix
Use
sync/atomic.Bool:No public-API change —
SetDisableProgress(bool)keeps the same signature. Callers and tests continue to pass a plain bool; the race-detector reports clean.Fixes #493