This commit is contained in:
Richard Ramos 2021-11-23 11:01:36 -04:00
parent 9e1fce8457
commit 6c721f7ffd
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F

View File

@ -227,13 +227,15 @@ func (d *DiscoveryV5) Start() error {
d.Lock()
defer d.Unlock()
d.wg.Wait() // Waiting for other go routines to stop
d.quit = make(chan struct{}, 1)
err := d.listen()
if err != nil {
return err
}
d.quit = make(chan struct{})
return nil
}
@ -241,11 +243,11 @@ func (d *DiscoveryV5) Stop() {
d.Lock()
defer d.Unlock()
close(d.quit)
d.listener.Close()
d.listener = nil
close(d.quit)
log.Info("Stopped Discovery V5")
d.wg.Wait()
@ -361,6 +363,8 @@ func (c *DiscoveryV5) Advertise(ctx context.Context, ns string, opts ...discover
}
func (d *DiscoveryV5) iterate(ctx context.Context, iterator enode.Iterator, limit int, doneCh chan struct{}) {
defer d.wg.Done()
for {
if len(d.peerCache.recs) >= limit {
break
@ -393,7 +397,6 @@ func (d *DiscoveryV5) iterate(ctx context.Context, iterator enode.Iterator, limi
}
}
d.wg.Done()
close(doneCh)
}