Merge pull request #653 from nspcc-dev/fix-net-locks-and-leaks

network: fix networking stalls caused by stale peers
This commit is contained in:
Roman Khimov 2020-02-10 18:51:56 +03:00 committed by GitHub
commit 0461827fa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,6 +27,7 @@ const (
)
var (
errGone = errors.New("the peer is gone already")
errStateMismatch = errors.New("tried to send protocol message before handshake completed")
errPingPong = errors.New("ping/pong timeout")
errUnexpectedPong = errors.New("pong message wasn't expected")
@ -78,7 +79,11 @@ func (p *TCPPeer) putPacketIntoQueue(queue chan<- []byte, msg []byte) error {
if !p.Handshaked() {
return errStateMismatch
}
queue <- msg
select {
case queue <- msg:
case <-p.done:
return errGone
}
return nil
}