Close peerInfo tasks channel (#4429)

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
This commit is contained in:
ledgerwatch 2022-06-10 11:59:31 +01:00 committed by GitHub
parent 1e3c90ba80
commit 43f5f0ae27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,6 +78,14 @@ func NewPeerInfo(peer *p2p.Peer, rw p2p.MsgReadWriter) *PeerInfo {
return p
}
func (pi *PeerInfo) Close() {
pi.lock.Lock()
defer pi.lock.Unlock()
if pi.tasks != nil {
close(pi.tasks)
}
}
func (pi *PeerInfo) ID() [64]byte {
return pi.peer.Pubkey()
}
@ -494,6 +502,7 @@ func NewGrpcServer(ctx context.Context, dialCandidates enode.Iterator, readNodeI
log.Trace(fmt.Sprintf("[%s] Start with peer", peerID))
peerInfo := NewPeerInfo(peer, rw)
defer peerInfo.Close()
defer ss.GoodPeers.Delete(peerID)
err := handShake(ctx, ss.GetStatus(), peerID, rw, protocol, protocol, func(bestHash common.Hash) error {