diff --git a/p2p/discover/lookup.go b/p2p/discover/lookup.go index 79b4d86144..ab825fb05d 100644 --- a/p2p/discover/lookup.go +++ b/p2p/discover/lookup.go @@ -111,7 +111,7 @@ func (it *lookup) startQueries() bool { // for the table to fill in this case, but there is no good mechanism for that // yet. if len(closest.entries) == 0 { - time.Sleep(1 * time.Second) + it.slowdown() } it.queries = 1 it.replyCh <- closest.entries @@ -131,6 +131,15 @@ func (it *lookup) startQueries() bool { return it.queries > 0 } +func (it *lookup) slowdown() { + sleep := time.NewTimer(1 * time.Second) + defer sleep.Stop() + select { + case <-sleep.C: + case <-it.tab.closeReq: + } +} + func (it *lookup) query(n *node, reply chan<- []*node) { fails := it.tab.db.FindFails(n.ID(), n.IP()) r, err := it.queryfunc(n)