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 Oct 12, 2018
1 parent b44d552 commit cd7c98f
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 cd7c98f

Please sign in to comment.