Merge pull request #2454 from cfromknecht/handle-write-errors
peer: handle message encoding errors on write
This commit is contained in:
commit
058b0e5767
20
peer.go
20
peer.go
@ -1367,13 +1367,25 @@ func (p *peer) writeMessage(msg lnwire.Message) error {
|
|||||||
|
|
||||||
// With the temp buffer created and sliced properly (length zero, full
|
// With the temp buffer created and sliced properly (length zero, full
|
||||||
// capacity), we'll now encode the message directly into this buffer.
|
// capacity), we'll now encode the message directly into this buffer.
|
||||||
n, err := lnwire.WriteMessage(b, msg, 0)
|
_, err := lnwire.WriteMessage(b, msg, 0)
|
||||||
atomic.AddUint64(&p.bytesSent, uint64(n))
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
p.conn.SetWriteDeadline(time.Now().Add(writeMessageTimeout))
|
// Compute and set the write deadline we will impose on the remote peer.
|
||||||
|
writeDeadline := time.Now().Add(writeMessageTimeout)
|
||||||
|
err = p.conn.SetWriteDeadline(writeDeadline)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Finally, write the message itself in a single swoop.
|
// Finally, write the message itself in a single swoop.
|
||||||
_, err = p.conn.Write(b.Bytes())
|
n, err := p.conn.Write(b.Bytes())
|
||||||
|
|
||||||
|
// Regardless of the error returned, record how many bytes were written
|
||||||
|
// to the wire.
|
||||||
|
atomic.AddUint64(&p.bytesSent, uint64(n))
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user