Skip to content

Commit

Permalink
Ensure that discovery producer is stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
dshulyak committed Sep 25, 2018
1 parent 6a1cd7f commit ff7c0e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion discovery/rendezvous.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions peers/peerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff7c0e0

Please sign in to comment.