From a7d9b0a5ae87a4fcedce0790ebad2f2a29af5056 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Mon, 15 Jul 2019 08:36:22 -0500 Subject: [PATCH] make sure workers are done when closing via a WaitGroup still running out of goroutines in race tests in CI, so hopefully this fixes that. --- executor.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/executor.go b/executor.go index 6131a8d71..bd48033da 100644 --- a/executor.go +++ b/executor.go @@ -20,6 +20,7 @@ import ( "fmt" "runtime" "sort" + "sync" "time" "github.com/pilosa/pilosa/pql" @@ -57,7 +58,8 @@ type executor struct { // Stores key/id translation data. TranslateStore TranslateStore - work chan job + workersWG sync.WaitGroup + work chan job } // executorOption is a functional option type for pilosa.Executor @@ -88,13 +90,18 @@ func newExecutor(opts ...executorOption) *executor { } } for i := 0; i < workerPoolSize; i++ { - go worker(e.work) + e.workersWG.Add(1) + go func() { + defer e.workersWG.Done() + worker(e.work) + }() } return e } func (e *executor) Close() error { close(e.work) + e.workersWG.Wait() return nil }