Commit f91baafb authored by Henry's avatar Henry

fixed two more

parent 006dd2ca
...@@ -68,11 +68,12 @@ func (bs *Bitswap) provideWorker(ctx context.Context) { ...@@ -68,11 +68,12 @@ func (bs *Bitswap) provideWorker(ctx context.Context) {
log.Debug("provideKeys channel closed") log.Debug("provideKeys channel closed")
return return
} }
ctx, _ := context.WithTimeout(ctx, provideTimeout) ctx, cancel := context.WithTimeout(ctx, provideTimeout)
err := bs.network.Provide(ctx, k) err := bs.network.Provide(ctx, k)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
cancel()
case <-ctx.Done(): case <-ctx.Done():
return return
} }
...@@ -136,12 +137,13 @@ func (bs *Bitswap) clientWorker(parent context.Context) { ...@@ -136,12 +137,13 @@ func (bs *Bitswap) clientWorker(parent context.Context) {
// NB: Optimization. Assumes that providers of key[0] are likely to // NB: Optimization. Assumes that providers of key[0] are likely to
// be able to provide for all keys. This currently holds true in most // be able to provide for all keys. This currently holds true in most
// every situation. Later, this assumption may not hold as true. // every situation. Later, this assumption may not hold as true.
child, _ := context.WithTimeout(req.ctx, providerRequestTimeout) child, cancel := context.WithTimeout(req.ctx, providerRequestTimeout)
providers := bs.network.FindProvidersAsync(child, keys[0], maxProvidersPerRequest) providers := bs.network.FindProvidersAsync(child, keys[0], maxProvidersPerRequest)
err := bs.sendWantlistToPeers(req.ctx, providers) err := bs.sendWantlistToPeers(req.ctx, providers)
if err != nil { if err != nil {
log.Debugf("error sending wantlist: %s", err) log.Debugf("error sending wantlist: %s", err)
} }
cancel()
// Wait for wantNewBlocks to finish // Wait for wantNewBlocks to finish
<-done <-done
......
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