Commit 64329ed1 authored by Jeromy's avatar Jeromy

make sure not to orphan any extra goroutines

parent 5fb913d6
......@@ -368,14 +368,19 @@ func (bs *bitswap) wantNewBlocks(ctx context.Context, bkeys []u.Key) {
for i, k := range bkeys {
message.AddEntry(k, kMaxPriority-i)
}
wg := sync.WaitGroup{}
for _, p := range bs.engine.Peers() {
wg.Add(1)
go func(p peer.ID) {
defer wg.Done()
err := bs.send(ctx, p, message)
if err != nil {
log.Debugf("Error sending message: %s", err)
}
}(p)
}
wg.Wait()
}
func (bs *bitswap) ReceiveError(err error) {
......
......@@ -90,7 +90,11 @@ func (bs *bitswap) clientWorker(parent context.Context) {
bs.wantlist.Add(k, kMaxPriority-i)
}
bs.wantNewBlocks(req.ctx, keys)
done := make(chan struct{})
go func() {
bs.wantNewBlocks(req.ctx, keys)
close(done)
}()
// NB: Optimization. Assumes that providers of key[0] are likely to
// be able to provide for all keys. This currently holds true in most
......@@ -101,6 +105,10 @@ func (bs *bitswap) clientWorker(parent context.Context) {
if err != nil {
log.Debugf("error sending wantlist: %s", err)
}
// Wait for wantNewBlocks to finish
<-done
case <-parent.Done():
return
}
......
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