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.
This commit is contained in:
Roman Khimov 2023-02-21 16:19:06 +03:00
parent 510bc91804
commit 4f708c037d

View file

@ -250,6 +250,16 @@ func (p *TCPPeer) handleQueues() {
p2pSkipCounter++ p2pSkipCounter++
} }
p.Disconnect(err) 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 // StartProtocol starts a long running background loop that interacts