Skip to content

Commit

Permalink
bitswap: Don't clear 'active' until Connect calls are finished
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <why@ipfs.io>
  • Loading branch information
whyrusleeping committed Sep 1, 2016
1 parent 6fdfaaf commit f640a44
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions exchange/bitswap/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,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()
Expand Down

0 comments on commit f640a44

Please sign in to comment.