From b9130108cf39188c6a17f80c00e00d8846695607 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Thu, 1 Sep 2016 08:26:59 -0700 Subject: [PATCH] bitswap: Don't clear 'active' until Connect calls are finished License: MIT Signed-off-by: Jeromy --- exchange/bitswap/workers.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exchange/bitswap/workers.go b/exchange/bitswap/workers.go index 4aa45791733..a7a218fb553 100644 --- a/exchange/bitswap/workers.go +++ b/exchange/bitswap/workers.go @@ -201,14 +201,18 @@ func (bs *Bitswap) providerQueryManager(ctx context.Context) { child, cancel := context.WithTimeout(e.Ctx, providerRequestTimeout) defer cancel() providers := bs.network.FindProvidersAsync(child, e.Key, maxProvidersPerRequest) + wg := &sync.WaitGroup{} for p := range providers { + wg.Add(1) go func(p peer.ID) { + defer wg.Done() err := bs.network.ConnectTo(child, p) if err != nil { log.Debug("failed to connect to provider %s: %s", p, err) } }(p) } + wg.Wait() activeLk.Lock() delete(active, e.Key) activeLk.Unlock()