Skip to content

bug: disableProgress global variable has data race (no atomic/mutex protection) #493

Description

@aftersnow

Description

In internal/pb/pb.go:33-40, the global disableProgress bool is written by SetDisableProgress() and read by Add() without any synchronization — no mutex, no sync/atomic.

During concurrent pull/push operations where multiple goroutines call Add() while SetDisableProgress() may also be called, this causes a data race detectable by go test -race.

Code

var (
    disableProgress bool  // unprotected global variable
)

func SetDisableProgress(disable bool) {
    disableProgress = disable  // unsynchronized write
}

func (p *ProgressBar) Add(...) io.Reader {
    if disableProgress {  // unsynchronized read
        return reader
    }
    // ...
}

Fix

Replace with atomic.Bool:

var disableProgress atomic.Bool

func SetDisableProgress(disable bool) {
    disableProgress.Store(disable)
}

// In Add():
if disableProgress.Load() {
    return reader
}

Severity

Critical — data race under concurrent usage, undefined behavior per Go memory model.

Activity

  1. added a commit that references this issue on Apr 20, 2026
    e8e9b36
  2. added a commit that references this issue on Apr 21, 2026
    306c518
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions