p2p: add error check to SetWriteDeadline call in rlpx

rlpx tries to send discreason to disconnected peer
 if the connection is net.Pipe (in-memory simulation)
 it hangs forever, since net.Pipe does not implement
 a write deadline. This commit adds error checking
 on the SetWriteDeadline call and only tries to send
 the disconnect reason message if there is no error
This commit is contained in:
zelig 2017-09-18 13:44:14 +02:00 committed by Anton Evangelatov
parent 6ffc6c6ef7
commit aaaf75d26e

View file

@ -108,8 +108,9 @@ func (t *rlpx) close(err error) {
// Tell the remote end why we're disconnecting if possible.
if t.rw != nil {
if r, ok := err.(DiscReason); ok && r != DiscNetworkError {
t.fd.SetWriteDeadline(time.Now().Add(discWriteTimeout))
SendItems(t.rw, discMsg, r)
if err = t.fd.SetWriteDeadline(time.Now().Add(discWriteTimeout)); err == nil {
SendItems(t.rw, discMsg, r)
}
}
}
t.fd.Close()