Skip to content

Commit

Permalink
chore_: use WaitGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
qfrank committed Mar 10, 2025
1 parent a4ca18a commit 5cf4377
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions wakuv2/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,11 @@ func (w *Waku) getDiscV5BootstrapNodes(ctx context.Context, addresses []string,
defer gocommon.LogOnPanic()
defer wg.Done()
if err := w.dnsDiscover(ctx, addr, retrieveENR, useOnlyDnsDiscCache); err != nil {
// prevent w.ctx in retryDnsDiscoveryWithBackoff from set to nil when w.Stop() is called
w.wg.Add(1)
go func() {
defer gocommon.LogOnPanic()
defer w.wg.Done()
w.retryDnsDiscoveryWithBackoff(ctx, addr, w.dnsDiscAsyncRetrievedSignal)
}()
}
Expand Down Expand Up @@ -514,13 +517,8 @@ func (w *Waku) retryDnsDiscoveryWithBackoff(ctx context.Context, addr string, su
}

t := time.NewTimer(backoff)
c := w.ctx
// c might be nil when w.Stop is invoked while this goroutine is running
if c == nil {
return
}
select {
case <-c.Done():
case <-w.ctx.Done():
t.Stop()
return
case <-t.C:
Expand Down

0 comments on commit 5cf4377

Please sign in to comment.