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

add mutex to progress for prevent race condition #81

Conversation

Haraguroicha
Copy link

it might not the best way to fix the race condition, but it fixed the overwritten in race condition and stable in thread safe state when many goroutine called progress render.

@coveralls
Copy link

coveralls commented May 30, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 8539348 on Haraguroicha:progress-add-more-mutex-to-prevent-race-condition into 50be2aa on jedib0t:master.

@jedib0t
Copy link
Owner

jedib0t commented May 30, 2019

That is a lot of additional mutex usage. Can you share a sample code where you see the race condition? Maybe there is a simpler solution that we can work out.

@Haraguroicha
Copy link
Author

Hi @jedib0t,

there is the data race warning message output during I'm created at least 3 gorouting to process the data with its progressbar, and it also might caused a hanging by rapidly calling tracker.Increment(1)

==================
WARNING: DATA RACE
Read at 0x00c0000a1010 by goroutine 23:
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:22 +0x1ed

Previous write at 0x00c0000a1010 by goroutine 20:
  github.com/jedib0t/go-pretty/progress.(*Progress).AppendTracker()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/progress.go:75 +0x1f6
==================
WARNING: DATA RACE
Read at 0x00c000368bf0 by goroutine 23:
  github.com/jedib0t/go-pretty/progress.(*Progress).extractDoneAndActiveTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:72 +0x328
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:43 +0xf4
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:23 +0x225

Previous write at 0x00c000368bf0 by goroutine 21:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:47 +0x96
==================
WARNING: DATA RACE
Write at 0x00c000107eb8 by goroutine 21:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:98 +0xdb

Previous read at 0x00c000107eb8 by goroutine 23:
  github.com/jedib0t/go-pretty/progress.(*Progress).extractDoneAndActiveTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:57 +0x140
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:43 +0xf4
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:23 +0x225
==================
WARNING: DATA RACE
Read at 0x00c0000a0fe0 by goroutine 21:
  github.com/jedib0t/go-pretty/progress.(*Progress).LengthActive()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/progress.go:102 +0x5f

Previous write at 0x00c0000a0fe0 by goroutine 23:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:55 +0x376
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:23 +0x225

==================
WARNING: DATA RACE
Read at 0x00c000107ed8 by goroutine 23:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerStats()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:240 +0x4bb
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerDone()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:182 +0x71c
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTracker()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:170 +0x4ce
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:53 +0x344
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:23 +0x225

Previous write at 0x00c000107ed8 by goroutine 21:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:99 +0x121

and here is a sample code I reproduced the same situation and log

code progressbar_test_sample.go

package main

import (
	"math/rand"
	"os"
	"os/signal"
	"sync"
	"syscall"
	"time"

	"github.com/jedib0t/go-pretty/progress"
)

func getProgress() bool {
	syncProgress.RLock()
	progress := (*progressWriter).IsRenderInProgress()
	syncProgress.RUnlock()
	return progress
}
func getLength() int {
	syncProgress.RLock()
	length := (*progressWriter).LengthActive()
	syncProgress.RUnlock()
	return length
}

func NewProgress() *progress.Writer {
	syncProgress.Lock()
	if progressRendered == false {
		go (*progressWriter).Render()
		progressRendered = true
	}
	syncProgress.Unlock()
	return progressWriter
}

func EndProgress() {
	for getProgress() {
		// for manual-stop mode, stop when there are no more active trackers
		if getLength() == 0 {
			(*progressWriter).Stop()
			syncProgress.Lock()
			progressRendered = false
			syncProgress.Unlock()
		}
		time.Sleep(time.Millisecond * 100)
	}
}

var progressWriter *progress.Writer
var syncProgress = sync.RWMutex{}
var progressRendered = false

func init() {
	pw := progress.NewWriter()
	pw.SetAutoStop(false)
	pw.SetSortBy(progress.SortByNone)
	pw.SetStyle(progress.StyleDefault)
	pw.SetTrackerPosition(progress.PositionRight)
	pw.SetUpdateFrequency(time.Millisecond * 100)
	pw.Style().Colors = progress.StyleColorsExample
	pw.Style().Options.PercentFormat = "%4.1f%%"
	progressWriter = &pw
}

func sample1() {
	var wg sync.WaitGroup
	pw := NewProgress()
	tracker := progress.Tracker{
		Message: "sample1",
		Total:   40,
		Units:   progress.UnitsDefault,
	}
	(*pw).AppendTracker(&tracker)
	for i := 1; i <= 40; i++ {
		wg.Add(1)
		go func() {
			defer tracker.Increment(1)
			defer wg.Done()
			time.Sleep(time.Duration(rand.Float64()*100) * time.Millisecond)
		}()
	}
	wg.Wait()
	EndProgress()
}

func sample2() {
	var wg sync.WaitGroup
	pw := NewProgress()
	tracker := progress.Tracker{
		Message: "sample2",
		Total:   20,
		Units:   progress.UnitsDefault,
	}
	(*pw).AppendTracker(&tracker)
	for i := 1; i <= 20; i++ {
		wg.Add(1)
		go func() {
			defer tracker.Increment(1)
			defer wg.Done()
			time.Sleep(time.Duration(rand.Float64()*200) * time.Millisecond)
		}()
	}
	wg.Wait()
	EndProgress()
}
func sample3() {
	var wg sync.WaitGroup
	pw := NewProgress()
	tracker := progress.Tracker{
		Message: "sample3",
		Total:   10,
		Units:   progress.UnitsDefault,
	}
	(*pw).AppendTracker(&tracker)
	for i := 1; i <= 10; i++ {
		wg.Add(1)
		go func() {
			defer tracker.Increment(1)
			defer wg.Done()
			time.Sleep(time.Duration(rand.Float64()*400) * time.Millisecond)
		}()
	}
	wg.Wait()
	EndProgress()
}

var swg sync.WaitGroup

func main() {
	go sample1()
	go sample2()
	go sample3()
	// Handle SIGINT and SIGTERM
	sig := make(chan os.Signal)
	signal.Notify(sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
	// Wait signal
	swg.Add(1)
	go func() {
		select {
		case s := <-sig:
			if s != nil {
				switch s {
				case syscall.SIGINT, syscall.SIGTERM:
					swg.Done()
				}
			}
		}
	}()
	swg.Wait()
	signal.Stop(sig)
	close(sig)
}

log

$ go run -race progressbar_test_sample.go
==================
WARNING: DATA RACE
Read at 0x00c00009e6c8 by goroutine 8:
  github.com/jedib0t/go-pretty/progress.(*Progress).AppendTracker()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/progress.go:67 +0x120
  main.sample2()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:95 +0x1a7

Previous write at 0x00c00009e6c8 by goroutine 7:
  github.com/jedib0t/go-pretty/progress.(*Progress).AppendTracker()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/progress.go:68 +0x4df
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:74 +0x1a7

Goroutine 8 (running) created at:
  main.main()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:132 +0x5e

Goroutine 7 (running) created at:
  main.main()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:131 +0x46
==================
==================
WARNING: DATA RACE
Read at 0x00c0000e00f0 by goroutine 24:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:47 +0x73
  main.sample1.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:81 +0xab

Previous write at 0x00c0000e00f0 by goroutine 49:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:47 +0x94
  main.sample1.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:81 +0xab

Goroutine 24 (running) created at:
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:77 +0x1f6

Goroutine 49 (finished) created at:
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:77 +0x1f6
==================
==================
WARNING: DATA RACE
Read at 0x00c0000f4070 by goroutine 30:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:47 +0x73
  main.sample2.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:102 +0xab

Previous write at 0x00c0000f4070 by goroutine 59:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:47 +0x94
  main.sample2.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:102 +0xab

Goroutine 30 (running) created at:
  main.sample2()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:98 +0x1f6

Goroutine 59 (finished) created at:
  main.sample2()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:98 +0x1f6
==================
==================
WARNING: DATA RACE
Read at 0x00c0000f4070 by goroutine 45:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:47 +0x73
  main.sample2.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:102 +0xab

Previous write at 0x00c0000f4070 by goroutine 59:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:47 +0x94
  main.sample2.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:102 +0xab

Goroutine 45 (running) created at:
  main.sample2()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:98 +0x1f6

Goroutine 59 (finished) created at:
  main.sample2()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:98 +0x1f6
==================
==================
WARNING: DATA RACE
Read at 0x00c00014e070 by goroutine 20:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:47 +0x73
  main.sample3.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:122 +0xab

Previous write at 0x00c00014e070 by goroutine 53:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:47 +0x94
  main.sample3.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:122 +0xab

Goroutine 20 (running) created at:
  main.sample3()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:118 +0x1f6

Goroutine 53 (finished) created at:
  main.sample3()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:118 +0x1f6
==================
==================
WARNING: DATA RACE
Read at 0x00c00009e720 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:22 +0x1ed

Previous write at 0x00c00009e720 by goroutine 10:
  github.com/jedib0t/go-pretty/progress.(*Progress).AppendTracker()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/progress.go:75 +0x1f6
  main.sample3()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:115 +0x1a7

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xeb
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x84

Goroutine 10 (running) created at:
  main.main()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:133 +0x76
==================
sample1 ... 95.0% [#################.] [38 in 101.187ms]
sample2 ... 50.0% [#########.........] [10 in 101.24ms]
sample3 ... 40.0% [#######...........] [4 in 100.752ms]
==================
WARNING: DATA RACE
Write at 0x00c0000e00b8 by goroutine 88:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:98 +0xd9
  main.sample1.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:81 +0xab

Previous read at 0x00c0000e00b8 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerStats()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:57 +0x493
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerProgress()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:207 +0x8b8
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTracker()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:173 +0x58d
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:53 +0x344
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:23 +0x225

Goroutine 88 (running) created at:
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:77 +0x1f6

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xeb
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x84
==================
==================
WARNING: DATA RACE
Read at 0x00c00009e6d0 by goroutine 7:
  github.com/jedib0t/go-pretty/progress.(*Progress).IsRenderInProgress()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/progress.go:92 +0x3e
  main.getProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:16 +0x7b
  main.EndProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:38 +0x42
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:84 +0x217

Previous write at 0x00c00009e6d0 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:19 +0xbc

Goroutine 7 (running) created at:
  main.main()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:131 +0x46

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xeb
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x84
==================
==================
WARNING: DATA RACE
Read at 0x00c00009e6f0 by goroutine 7:
  github.com/jedib0t/go-pretty/progress.(*Progress).LengthActive()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/progress.go:102 +0x5f
  main.getLength()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:22 +0x7b
  main.EndProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:40 +0x51
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:84 +0x217

Previous write at 0x00c00009e6f0 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:55 +0x376
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:23 +0x225

Goroutine 7 (running) created at:
  main.main()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:131 +0x46

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xeb
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x84
==================
==================
WARNING: DATA RACE
Write at 0x00c0000f4038 by goroutine 14:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:98 +0xd9
  main.sample2.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:102 +0xab

Previous read at 0x00c0000f4038 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerStats()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:57 +0x493
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerProgress()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:207 +0x8b8
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTracker()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:173 +0x58d
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:53 +0x344
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:23 +0x225

Goroutine 14 (running) created at:
  main.sample2()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:98 +0x1f6

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xeb
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x84
==================
==================
WARNING: DATA RACE
Read at 0x00c0000e00d8 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerStats()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:240 +0x4bb
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerDone()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:182 +0x71c
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTracker()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:170 +0x4ce
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:47 +0x196
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:23 +0x225

Previous write at 0x00c0000e00d8 by goroutine 88:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:99 +0x11f
  main.sample1.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:81 +0xab

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xeb
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x84

Goroutine 88 (finished) created at:
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:77 +0x1f6
==================
==================
WARNING: DATA RACE
Read at 0x00c0000f4058 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerStats()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:240 +0x4bb
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerDone()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:182 +0x71c
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTracker()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:170 +0x4ce
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:47 +0x196
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:23 +0x225

Previous write at 0x00c0000f4058 by goroutine 14:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:99 +0x11f
  main.sample2.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:102 +0xab

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xeb
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x84

Goroutine 14 (finished) created at:
sample1 ... done! [40 in 104ms]
sample2 ... done! [20 in 189ms]
sample3 ... 80.0% [##############....] [8 in 300.331ms]
==================
WARNING: DATA RACE
Write at 0x00c00014e038 by goroutine 41:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:98 +0xd9
  main.sample3.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:122 +0xab

Previous read at 0x00c00014e038 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerStats()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:57 +0x493
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerProgress()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:207 +0x8b8
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTracker()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:173 +0x58d
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:53 +0x344
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:23 +0x225

Goroutine 41 (running) created at:
  main.sample3()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:118 +0x1f6

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xeb
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x84
==================
==================
WARNING: DATA RACE
Read at 0x00c00014e058 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerStats()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:240 +0x4bb
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerDone()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:182 +0x71c
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTracker()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:170 +0x4ce
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:47 +0x196
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:23 +0x225

Previous write at 0x00c00014e058 by goroutine 41:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/tracker.go:99 +0x11f
  main.sample3.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:122 +0xab

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xeb
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x84

Goroutine 41 (finished) created at:
  main.sample3()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:118 +0x1f6
sample3 ... done! [10 in 346ms]
==================
WARNING: DATA RACE
Read at 0x00c00009e688 by goroutine 7:
  github.com/jedib0t/go-pretty/progress.(*Progress).Stop()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/progress.go:190 +0x6a
  main.EndProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:41 +0x98
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:84 +0x217

Previous write at 0x00c00009e688 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).initForRender()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/progress.go:208 +0xba
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/pkg/mod/github.com/jedib0t/go-pretty@v4.1.0+incompatible/progress/render.go:15 +0x76

Goroutine 7 (running) created at:
  main.main()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:131 +0x46

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xeb
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x84
==================
^CFound 15 data race(s)
exit status 66

@Haraguroicha
Copy link
Author

after my latest update of #62aac18, it fixed the data race with same sample code w/o any data race warnings like this below

$ go run -race progressbar_test_sample.go
sample1 ... done! [40 in 105ms]
sample2 ... done! [20 in 198ms]
sample3 ... done! [10 in 349ms]
^C

@jedib0t
Copy link
Owner

jedib0t commented May 30, 2019

Weird. Your sample code doesn't seem to throw any race conditions on my machine. Can you share your system details? OS? Golang version?

@Haraguroicha
Copy link
Author

Haraguroicha commented May 30, 2019

Here is

image

@jedib0t
Copy link
Owner

jedib0t commented May 30, 2019

Cool looking prompt! :)

I'm running golang 1.10 and am not able to reproduce the bug. I'll install 1.12.5 and try it.

@Haraguroicha
Copy link
Author

I'm using go version go1.10.8 linux/amd64 also reproduce same condition and makes me hanging

$ go run -race progressbar_test_sample.go
==================
WARNING: DATA RACE
Read at 0x00c4200a4458 by goroutine 8:
  github.com/jedib0t/go-pretty/progress.(*Progress).AppendTracker()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/progress.go:67 +0x97
  main.sample2()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:95 +0x19d

Previous write at 0x00c4200a4458 by goroutine 7:
  github.com/jedib0t/go-pretty/progress.(*Progress).AppendTracker()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/progress.go:68 +0x478
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:74 +0x19d

Goroutine 8 (running) created at:
  main.main()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:132 +0x5e

Goroutine 7 (running) created at:
  main.main()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:131 +0x46
==================
==================
WARNING: DATA RACE
Read at 0x00c4200e60f0 by goroutine 26:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:47 +0x6e
  main.sample1.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:81 +0xab

Previous write at 0x00c4200e60f0 by goroutine 56:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:47 +0x8f
  main.sample1.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:81 +0xab

Goroutine 26 (running) created at:
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:77 +0x1ec

Goroutine 56 (finished) created at:
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:77 +0x1ec
==================
==================
WARNING: DATA RACE
Read at 0x00c4200f4070 by goroutine 59:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:47 +0x6e
  main.sample2.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:102 +0xab

Previous write at 0x00c4200f4070 by goroutine 49:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:47 +0x8f
  main.sample2.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:102 +0xab

Goroutine 59 (running) created at:
  main.sample2()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:98 +0x1ec

Goroutine 49 (finished) created at:
  main.sample2()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:98 +0x1ec
==================
==================
WARNING: DATA RACE
Read at 0x00c42012a070 by goroutine 45:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:47 +0x6e
  main.sample3.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:122 +0xab

Previous write at 0x00c42012a070 by goroutine 24:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:47 +0x8f
  main.sample3.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:122 +0xab

Goroutine 45 (running) created at:
  main.sample3()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:118 +0x1ec

Goroutine 24 (finished) created at:
  main.sample3()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:118 +0x1ec
==================
==================
WARNING: DATA RACE
Read at 0x00c4200a44b0 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:22 +0x1e9

Previous write at 0x00c4200a44b0 by goroutine 10:
  github.com/jedib0t/go-pretty/progress.(*Progress).AppendTracker()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/progress.go:75 +0x182
  main.sample3()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:115 +0x19d

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xe8
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x7b

Goroutine 10 (running) created at:
  main.main()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:133 +0x76
==================
sample1 ... 90.0% [################..] [36 in 101.049ms]
sample2 ... 50.0% [#########.........] [10 in 101.203ms]
sample3 ... 20.0% [###...............] [2 in 100.628ms]
==================
WARNING: DATA RACE
Read at 0x00c4200a4460 by goroutine 7:
  github.com/jedib0t/go-pretty/progress.(*Progress).IsRenderInProgress()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/progress.go:92 +0x3c
  main.getProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:16 +0x76
  main.EndProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:38 +0x42
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:84 +0x20d

Previous write at 0x00c4200a4460 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:19 +0xbe

Goroutine 7 (running) created at:
  main.main()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:131 +0x46

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xe8
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x7b
==================
==================
WARNING: DATA RACE
Read at 0x00c4200a4480 by goroutine 7:
  github.com/jedib0t/go-pretty/progress.(*Progress).LengthActive()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/progress.go:102 +0x5d
  main.getLength()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:22 +0x76
  main.EndProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:40 +0x53
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:84 +0x20d

Previous write at 0x00c4200a4480 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:55 +0x301
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:23 +0x210

Goroutine 7 (running) created at:
  main.main()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:131 +0x46

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xe8
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x7b
==================
==================
WARNING: DATA RACE
Write at 0x00c4200f4038 by goroutine 52:
  github.com/jedib0t/go-pretty/progress.(*Tracker).stop()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:98 +0x40
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:49 +0xf8
  main.sample2.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:102 +0xab

Previous read at 0x00c4200f4038 by goroutine 69:
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:46 +0x40
  main.sample2.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:102 +0xab

Goroutine 52 (running) created at:
  main.sample2()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:98 +0x1ec

Goroutine 69 (finished) created at:
  main.sample2()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:98 +0x1ec
==================
==================
WARNING: DATA RACE
Read at 0x00c4200f4058 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerStats()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:240 +0x294
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerDone()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:182 +0x3f3
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTracker()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:170 +0x2f3
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:47 +0x135
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:23 +0x210

Previous write at 0x00c4200f4058 by goroutine 52:
  github.com/jedib0t/go-pretty/progress.(*Tracker).stop()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:99 +0x86
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:49 +0xf8
  main.sample2.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:102 +0xab

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xe8
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x7b

Goroutine 52 (finished) created at:
sample2 ... done! [20 in 200ms]
sample1 ... 95.0% [#################.] [38 in 202.113ms]
sample3 ... 70.0% [############......] [7 in 201.834ms]
==================
WARNING: DATA RACE
Write at 0x00c42012a038 by goroutine 36:
  github.com/jedib0t/go-pretty/progress.(*Tracker).stop()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:98 +0x40
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:49 +0xf8
  main.sample3.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:122 +0xab

Previous read at 0x00c42012a038 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerStats()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:57 +0x26a
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerProgress()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:207 +0x517
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTracker()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:173 +0x3b0
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:53 +0x2d2
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:23 +0x210

Goroutine 36 (running) created at:
  main.sample3()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:118 +0x1ec

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xe8
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x7b
==================
==================
WARNING: DATA RACE
Read at 0x00c42012a058 by goroutine 9:
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerStats()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:240 +0x294
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackerDone()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:182 +0x3f3
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTracker()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:170 +0x2f3
  github.com/jedib0t/go-pretty/progress.(*Progress).renderTrackers()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:47 +0x135
  github.com/jedib0t/go-pretty/progress.(*Progress).Render()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/render.go:23 +0x210

Previous write at 0x00c42012a058 by goroutine 36:
  github.com/jedib0t/go-pretty/progress.(*Tracker).stop()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:99 +0x86
  github.com/jedib0t/go-pretty/progress.(*Tracker).Increment()
      /home/haraguroicha/go/src/github.com/jedib0t/go-pretty/progress/tracker.go:49 +0xf8
  main.sample3.func1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:122 +0xab

Goroutine 9 (running) created at:
  main.NewProgress()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:30 +0xe8
  main.sample1()
      /home/haraguroicha/progressSample/progressbar_test_sample.go:68 +0x7b

Goroutine 36 (finished) created at:
  main.sample3()
sample3 ... done! [10 in 274ms]
sample1 ... 95.0% [#################.] [38 in 18.400961s]
Found 11 data race(s)
exit status 66

@Haraguroicha
Copy link
Author

tested with go version go1.10.4 linux/amd64 from apt install has same result
my golang version of go 1.10.8 and 1.12.5 are install from Linuxbrew

@jedib0t
Copy link
Owner

jedib0t commented May 30, 2019

Hey. I tried reproducing it in go1.10.4 in WSL Ubuntu-18.04.2 and also bare Ubuntu-18.04.2 (both x86_64) and wasn't able to. I'll try more versions this week and let you know if I can reproduce it and find the root-cause.

BTW, I see that the sample code you pasted is calling Render() three times (once in each goroutine via NewProgress()). You are supposed to call go progresswriter.Render() only once - definitely not multiple times in parallel.

Ideally, this is how you do progress tracking using this package:

  1. Initialize one progress.Writer object pw with or without AutoStop
  2. Call go pw.Render()
  3. Append trackers for each parallel task you are executing
  4. Call pw.Stop() once all your tasks are done (if you haven't enabled AutoStop)

Sample usage is at cmd/demo-progress/demo.go.

@jedib0t
Copy link
Owner

jedib0t commented May 30, 2019

Just noticed the -race flag you used with go run. I can see the race conditions now. Thanks for reporting the bug and coding up a fix. Will take a deeper look to see if this can be solved differently.

@jedib0t
Copy link
Owner

jedib0t commented May 30, 2019

Hey @Haraguroicha can you please rebase your branch? I'll merge your changes once done.

jedib0t added a commit that referenced this pull request May 30, 2019
jedib0t added a commit that referenced this pull request May 30, 2019
jedib0t added a commit that referenced this pull request May 30, 2019
jedib0t added a commit that referenced this pull request May 30, 2019
@jedib0t jedib0t closed this in #83 May 30, 2019
jedib0t added a commit that referenced this pull request May 30, 2019
@jedib0t
Copy link
Owner

jedib0t commented May 30, 2019

Hey @Haraguroicha --- I've used your code and added some fixes on top with #83 and merged it into master. Will cut a new tag soon that you can use with all these fixes.

I really appreciate you taking the time to debug and fix the unsafe accesses in the code. Thanks a ton!

@jedib0t
Copy link
Owner

jedib0t commented May 30, 2019

Hey @Haraguroicha --- please use tag v4.2.0 to get the code with the fixes discussed above: https://github.com/jedib0t/go-pretty/releases/tag/v4.2.0

@Haraguroicha
Copy link
Author

Hi @jedib0t, in my sample code of NewProgress() is called three times by triggered as goroutine, but go progressWriter.Render() is only called once, here is a lock and a flag to promise that will only called once Render() not three.

func NewProgress() *progress.Writer {
	syncProgress.Lock()
	if progressRendered == false {
		go (*progressWriter).Render()
		progressRendered = true
	}
	syncProgress.Unlock()
	return progressWriter
}

@Haraguroicha
Copy link
Author

Oops, I saw you have merged as tag v4.2.0 after I send the last comment, thanks!

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

Successfully merging this pull request may close these issues.

3 participants