Ensure that discovery producer is stopped

This commit is contained in:
Dmitry 2018-09-24 09:52:26 +03:00 committed by Dmitry Shulyak
parent 6a1cd7f2b0
commit ff7c0e0a17
2 changed files with 14 additions and 4 deletions

View File

@ -192,8 +192,18 @@ func (r *Rendezvous) Discover(
log.Debug("converted enr to", "ENODE", n.String())
if err != nil {
log.Warn("error converting enr record to node", "err", err)
continue
}
select {
case found <- n:
case newPeriod, ok := <-period:
// closing a period channel is a signal to producer that consumer exited
ticker.Stop()
if !ok {
return nil
}
ticker = time.NewTicker(newPeriod)
}
found <- n
}
}
}

View File

@ -201,12 +201,12 @@ func (p *PeerPool) stopDiscovery(server *p2p.Server) {
return
}
if err := p.discovery.Stop(); err != nil {
log.Error("discovery errored when stopping", "err", err)
}
for _, t := range p.topics {
t.StopSearch(server)
}
if err := p.discovery.Stop(); err != nil {
log.Error("discovery errored when was closed", "err", err)
}
p.mu.Lock()
p.timeout = nil