From 6b9d7d362961d257277641bfb57f3fa89e1345dc Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Tue, 30 Nov 2021 16:01:19 -0500 Subject: [PATCH] Fix deadlock in skip-on-error case. No issue # Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- throttle.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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() { -- 2.30.2