From: Tom Clegg Date: Tue, 30 Nov 2021 21:01:19 +0000 (-0500) Subject: Fix deadlock in skip-on-error case. X-Git-Url: https://git.arvados.org/lightning.git/commitdiff_plain/6b9d7d362961d257277641bfb57f3fa89e1345dc Fix deadlock in skip-on-error case. No issue # Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- diff --git a/throttle.go b/throttle.go index ce3279dd33..8b087eeae2 100644 --- a/throttle.go +++ b/throttle.go @@ -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() {