From 8d96f0491041edc6179850c62be200a103f7732c Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 17 Jan 2020 11:29:16 +0100 Subject: [PATCH] fix(p2p): ensure Server.loop is ticking even if discovery hangs #20573 This is a temporary fix for a problem which started happening when the dialer was changed to read nodes from an enode.Iterator. Before the iterator change, discovery queries would always return within a couple seconds even if there was no Internet access. Since the iterator won't return unless a node is actually found, discoverTask can take much longer. This means that the 'emergency connect' logic might not execute in time, leading to a stuck node. --- p2p/server.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/p2p/server.go b/p2p/server.go index 03d7b8ef955..3dd49cb2e2f 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -632,9 +632,12 @@ func (srv *Server) run(dialstate dialer) { inboundCount = 0 trusted = make(map[enode.ID]bool, len(srv.TrustedNodes)) taskdone = make(chan task, maxActiveDialTasks) + tick = time.NewTicker(30 * time.Second) runningTasks []task queuedTasks []task // tasks that can't run yet ) + defer tick.Stop() + // Put trusted nodes into a map to speed up checks. // Trusted peers are loaded on startup or added via AddTrustedPeer RPC. for _, n := range srv.TrustedNodes { @@ -676,6 +679,9 @@ running: scheduleTasks() select { + case <-tick.C: + // This is just here to ensure the dial scheduler runs occasionally. + case <-srv.quit: // The server was stopped. Run the cleanup logic. break running