Skip to content

Commit

Permalink
p2p: avoid busy-loop on temporary errors
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Nov 19, 2020
1 parent 2808046 commit d4af4c3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -869,6 +872,7 @@ func (srv *Server) listenLoop() {
}
break
}
tmpErrors = 0

remoteIP := netutil.AddrIP(fd.RemoteAddr())
if err := srv.checkInboundConn(fd, remoteIP); err != nil {
Expand Down

0 comments on commit d4af4c3

Please sign in to comment.