Fix deadlock in skip-on-error case.
authorTom Clegg <tom@curii.com>
Tue, 30 Nov 2021 21:01:19 +0000 (16:01 -0500)
committerTom Clegg <tom@curii.com>
Tue, 30 Nov 2021 21:01:19 +0000 (16:01 -0500)
No issue #

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

throttle.go

index ce3279dd3398d76886c9f40cb2c279114d08d205..8b087eeae269787bf6367d46cc4eae3e9f73cefe 100644 (file)
@@ -19,7 +19,12 @@ type throttle struct {
 }
 
 func (t *throttle) Acquire() {
-       t.setupOnce.Do(func() { t.ch = make(chan bool, t.Max) })
+       t.setupOnce.Do(func() {
+               if t.Max < 1 {
+                       panic("throttle.Max < 1")
+               }
+               t.ch = make(chan bool, t.Max)
+       })
        t.wg.Add(1)
        t.ch <- true
 }
@@ -48,6 +53,7 @@ func (t *throttle) Wait() error {
 func (t *throttle) Go(f func() error) error {
        t.Acquire()
        if t.Err() != nil {
+               t.Release()
                return t.Err()
        }
        go func() {