From 84a3474fc5bf4e82c2a2dade59d7de826905bff4 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 24 Dec 2020 14:38:58 +0300 Subject: [PATCH] network: set timeout on write Fix a bug occuring under high load when node hangs during this write. --- pkg/network/tcp_peer.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/network/tcp_peer.go b/pkg/network/tcp_peer.go index f55a3954b..f8c29d61d 100644 --- a/pkg/network/tcp_peer.go +++ b/pkg/network/tcp_peer.go @@ -195,6 +195,7 @@ func (p *TCPPeer) handleQueues() { var p2pSkipCounter uint32 const p2pSkipDivisor = 4 + var writeTimeout = time.Duration(p.server.chain.GetConfig().SecondsPerBlock) * time.Second for { var msg []byte @@ -228,6 +229,10 @@ func (p *TCPPeer) handleQueues() { case msg = <-p.sendQ: } } + err = p.conn.SetWriteDeadline(time.Now().Add(writeTimeout)) + if err != nil { + break + } _, err = p.conn.Write(msg) if err != nil { break