From d4af4c3890ef8af56091016593e07a7b6dceb0c7 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 19 Nov 2020 12:21:46 +0100 Subject: [PATCH 1/2] p2p: avoid busy-loop on temporary errors --- p2p/server.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/p2p/server.go b/p2p/server.go index dd52297f8a9c..e6cdeb34cea5 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -854,13 +854,16 @@ func (srv *Server) listenLoop() { <-slots var ( - fd net.Conn - err error + fd net.Conn + err error + tmpErrors = uint64(0) ) for { fd, err = srv.listener.Accept() - if netutil.IsTemporaryError(err) { + if netutil.IsTemporaryError(err) && tmpErrors < 200 { srv.log.Debug("Temporary read error", "err", err) + tmpErrors++ + time.Sleep(time.Millisecond * 10) continue } else if err != nil { srv.log.Debug("Read error", "err", err) @@ -869,6 +872,7 @@ func (srv *Server) listenLoop() { } break } + tmpErrors = 0 remoteIP := netutil.AddrIP(fd.RemoteAddr()) if err := srv.checkInboundConn(fd, remoteIP); err != nil { From a418259aaa18e5a01d010b2bd3838adc7d062996 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Fri, 20 Nov 2020 12:22:51 +0100 Subject: [PATCH 2/2] p2p: address review concerns --- p2p/server.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/p2p/server.go b/p2p/server.go index e6cdeb34cea5..275cb5ea5c34 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -854,16 +854,18 @@ func (srv *Server) listenLoop() { <-slots var ( - fd net.Conn - err error - tmpErrors = uint64(0) + fd net.Conn + err error + lastLog time.Time ) for { fd, err = srv.listener.Accept() - if netutil.IsTemporaryError(err) && tmpErrors < 200 { - srv.log.Debug("Temporary read error", "err", err) - tmpErrors++ - time.Sleep(time.Millisecond * 10) + if netutil.IsTemporaryError(err) { + if time.Since(lastLog) > 1*time.Second { + srv.log.Debug("Temporary read error", "err", err) + lastLog = time.Now() + } + time.Sleep(time.Millisecond * 200) continue } else if err != nil { srv.log.Debug("Read error", "err", err) @@ -872,7 +874,6 @@ func (srv *Server) listenLoop() { } break } - tmpErrors = 0 remoteIP := netutil.AddrIP(fd.RemoteAddr()) if err := srv.checkInboundConn(fd, remoteIP); err != nil {