From 0957393047e15c9b58b41f479d0bd7788ead2201 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Tue, 9 May 2017 12:27:41 +0200 Subject: [PATCH] eth/filters: add WaitGroup to serveMatcher --- eth/filters/filter.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/eth/filters/filter.go b/eth/filters/filter.go index a4e3e88349..5fc918c30b 100644 --- a/eth/filters/filter.go +++ b/eth/filters/filter.go @@ -19,6 +19,7 @@ package filters import ( "context" "math/big" + "sync" "time" "github.com/ethereum/go-ethereum/common" @@ -128,10 +129,13 @@ func (f *Filter) Find(ctx context.Context) (logs []*types.Log, err error) { // serveMatcher serves the bloomBits matcher by fetching the requested vectors // through the filter backend -func (f *Filter) serveMatcher(ctx context.Context, stop chan struct{}) chan error { +func (f *Filter) serveMatcher(ctx context.Context, stop chan struct{}, wg *sync.WaitGroup) chan error { errChn := make(chan error) + wg.Add(10) for i := 0; i < 10; i++ { go func(i int) { + defer wg.Done() + for { b, s := f.matcher.NextRequest(stop) if s == nil { @@ -187,9 +191,12 @@ func (f *Filter) getLogs(ctx context.Context, start, end uint64) (logs []*types. } stop := make(chan struct{}) - defer close(stop) + var wg sync.WaitGroup matches := f.matcher.GetMatches(start, e, stop) - errChn := f.serveMatcher(ctx, stop) + errChn := f.serveMatcher(ctx, stop, &wg) + + defer wg.Wait() + defer close(stop) loop: for {