From f837321908efd2fa290b238132fc3711cfe3383e Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 27 Apr 2023 12:30:27 +0200 Subject: [PATCH] only using one context in findPeers --- share/availability/discovery/discovery.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/share/availability/discovery/discovery.go b/share/availability/discovery/discovery.go index f5b1e3a460..19bf9cb9f2 100644 --- a/share/availability/discovery/discovery.go +++ b/share/availability/discovery/discovery.go @@ -274,15 +274,15 @@ func (d *Discovery) findPeers(ctx context.Context) { log.Infow("below soft peer limit, discovering peers", "amount", d.set.Limit()) // we use errgroup as it obeys the context - wg, wgCtx := errgroup.WithContext(ctx) + wg, findCtx := errgroup.WithContext(ctx) + findCtx, findCancel := context.WithCancel(findCtx) + defer findCancel() + // limit to minimize chances of overreaching the limit wg.SetLimit(d.set.Limit()) - for d.set.Size() < d.set.Limit() && wgCtx.Err() == nil { + for d.set.Size() < d.set.Limit() && findCtx.Err() == nil { log.Debugw("finding peers", "remaining", d.set.Limit()-d.set.Size()) - findCtx, findCancel := context.WithCancel(wgCtx) - defer findCancel() - peers, err := d.disc.FindPeers(findCtx, topic) if err != nil { log.Warn(err)