Skip to content

Commit

Permalink
close the connection on partial writes
Browse files Browse the repository at this point in the history
fixes #7 (not the best way but it works)
  • Loading branch information
Stebalien committed Sep 14, 2018
1 parent 17259f2 commit fd3b3b3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions multiplex.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,22 @@ func (mp *Multiplex) sendMsg(header uint64, data []byte, dl time.Time) error {
n += binary.PutUvarint(buf[n:], uint64(len(data)))
n += copy(buf[n:], data)

_, err := mp.con.Write(buf[:n])
if err != nil {
written, err := mp.con.Write(buf[:n])
if err != nil && written > 0 {
// Bail. We've written partial message and can't do anything
// about this.
mp.con.Close()
return err
}

if !dl.IsZero() {
if err := mp.con.SetWriteDeadline(time.Time{}); err != nil {
return err
// only return this error if we don't *already* have an error from the write.
if err2 := mp.con.SetWriteDeadline(time.Time{}); err == nil && err2 != nil {
return err2
}
}

return nil
return err
}

func (mp *Multiplex) nextChanID() uint64 {
Expand Down

0 comments on commit fd3b3b3

Please sign in to comment.