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

Race condition with dynamic max #119

Closed
nsagnett opened this issue Apr 1, 2022 · 3 comments
Closed

Race condition with dynamic max #119

nsagnett opened this issue Apr 1, 2022 · 3 comments

Comments

@nsagnett
Copy link

nsagnett commented Apr 1, 2022

Hello,

I perform a race condition when I try to setup a dynamic max (like get requests with pagination for example)

To reproduce:

	var (
		bar    = progressbar.Default(0, "Test dynamic max")
		wg     = &sync.WaitGroup{}
		length = 1000
	)
	wg.Add(length)
	for i := 0; i < length; i++ {
		bar.ChangeMax64(int64(i + 1))
		go func(b *progressbar.ProgressBar) {
			defer b.Add(1)
			defer wg.Done()

			time.Sleep(3 * time.Second)
		}(bar)
		time.Sleep(time.Second)
	}
	wg.Wait()

After checking code, it seems missing mutex around progress bar max when ChangeMax64 called

Thanks!

@schollz
Copy link
Owner

schollz commented Apr 14, 2022

Could you submit a PR?

@mxey
Copy link
Contributor

mxey commented May 7, 2024

#183

@mxey
Copy link
Contributor

mxey commented Sep 26, 2024

My PR has been merged, this issue is fixed. Please close :)

@schollz schollz closed this as completed Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants