From 4f708c037d0a874c6536a06d9bf0222367dc5df2 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 21 Feb 2023 16:19:06 +0300 Subject: [PATCH] network: drain send queues on peer disconnection Fix potential memory leak with a lot of connected clients that keep requesting things from node and then disconnect. --- pkg/network/tcp_peer.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/network/tcp_peer.go b/pkg/network/tcp_peer.go index 6de3abe74..72e80aefe 100644 --- a/pkg/network/tcp_peer.go +++ b/pkg/network/tcp_peer.go @@ -250,6 +250,16 @@ func (p *TCPPeer) handleQueues() { p2pSkipCounter++ } p.Disconnect(err) +drainloop: + for { + select { + case <-p.hpSendQ: + case <-p.p2pSendQ: + case <-p.sendQ: + default: + break drainloop + } + } } // StartProtocol starts a long running background loop that interacts