From 53e73ceba21bf2ea9cf54fbe4ec42335519a38f0 Mon Sep 17 00:00:00 2001 From: Scott Miller Date: Fri, 16 Dec 2022 11:35:24 -0600 Subject: [PATCH] Use a cleaner worker pattern (#18422) --- vault/core.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/vault/core.go b/vault/core.go index cd1769aa6..2f8b80568 100644 --- a/vault/core.go +++ b/vault/core.go @@ -2398,25 +2398,22 @@ func (c *Core) postUnseal(ctx context.Context, ctxCancelFunc context.CancelFunc, v() } } else { - workerChans := make([]chan func(), postUnsealFuncConcurrency) + jobs := make(chan func()) var wg sync.WaitGroup for i := 0; i < postUnsealFuncConcurrency; i++ { - workerChans[i] = make(chan func()) - go func(i int) { - for v := range workerChans[i] { + go func() { + for v := range jobs { v() wg.Done() } - }(i) + }() } - for i, v := range c.postUnsealFuncs { + for _, v := range c.postUnsealFuncs { wg.Add(1) - workerChans[i%postUnsealFuncConcurrency] <- v - } - for i := 0; i < postUnsealFuncConcurrency; i++ { - close(workerChans[i]) + jobs <- v } wg.Wait() + close(jobs) } if atomic.LoadUint32(c.sealMigrationDone) == 1 {