Skip to content

Commit

Permalink
only using one context in findPeers
Browse files Browse the repository at this point in the history
  • Loading branch information
distractedm1nd committed Apr 27, 2023
1 parent 2ba8832 commit f837321
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions share/availability/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f837321

Please sign in to comment.