Commit 1b099641 authored by Jeromy's avatar Jeromy

bitswap: Don't clear 'active' until Connect calls are finished

License: MIT
Signed-off-by: default avatarJeromy <why@ipfs.io>
parent 3fbf157a
...@@ -201,14 +201,18 @@ func (bs *Bitswap) providerQueryManager(ctx context.Context) { ...@@ -201,14 +201,18 @@ func (bs *Bitswap) providerQueryManager(ctx context.Context) {
child, cancel := context.WithTimeout(e.Ctx, providerRequestTimeout) child, cancel := context.WithTimeout(e.Ctx, providerRequestTimeout)
defer cancel() defer cancel()
providers := bs.network.FindProvidersAsync(child, e.Key, maxProvidersPerRequest) providers := bs.network.FindProvidersAsync(child, e.Key, maxProvidersPerRequest)
wg := &sync.WaitGroup{}
for p := range providers { for p := range providers {
wg.Add(1)
go func(p peer.ID) { go func(p peer.ID) {
defer wg.Done()
err := bs.network.ConnectTo(child, p) err := bs.network.ConnectTo(child, p)
if err != nil { if err != nil {
log.Debug("failed to connect to provider %s: %s", p, err) log.Debug("failed to connect to provider %s: %s", p, err)
} }
}(p) }(p)
} }
wg.Wait()
activeLk.Lock() activeLk.Lock()
delete(active, e.Key) delete(active, e.Key)
activeLk.Unlock() activeLk.Unlock()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment