Skip to content

Commit ac3b2b7

Browse files
craig[bot]srosenberg
andcommitted
Merge #149448
149448: roachprod: fix race condition in ui/spinner r=golgeek,herkolategan a=srosenberg The goroutine inside `Spinner.Start` could result in `panic: sync: negative WaitGroup counter`. The race can occur under specific scheduling. It was observed while running `roachtest` in local mode with `--count 1000000`. The actual race occurs when `Spinner.Stop` is executed _before_ the goroutine exits. Specifically, `waitGroup.Wait` is invoked _after_ `waitgroup.Add`, thereby resetting the semaphore. Finally, `waitgroup.Done` is executed by `defer`, causing the panic. The fix moves `waitGroup.Add` outside of the goroutine. P.S.: SA2000 [1] only checks for cases where `waitgroup.Add` is the first statement [2]. None of the other linters pick this up. [1] https://staticcheck.dev/docs/checks/#SA2000 [2] dominikh/go-tools#360 (comment) Epic: none Release note: None Co-authored-by: Stan Rosenberg <[email protected]>
2 parents 2b4bb44 + 26dd1ef commit ac3b2b7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pkg/roachprod/ui/spinner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ func (s *Spinner) Start() func() {
118118
fmt.Fprintf(s.out, "\n")
119119
}
120120
}
121+
s.waitGroup.Add(1)
121122
go func() {
122123
defer s.waitGroup.Done()
123-
s.waitGroup.Add(1)
124124

125125
var writer Writer
126126
tickerDuration := 100 * time.Millisecond

0 commit comments

Comments
 (0)