Skip to content

Commit fd3b3b3

Browse files
committed
close the connection on partial writes
fixes #7 (not the best way but it works)
1 parent 17259f2 commit fd3b3b3

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

multiplex.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,22 @@ func (mp *Multiplex) sendMsg(header uint64, data []byte, dl time.Time) error {
143143
n += binary.PutUvarint(buf[n:], uint64(len(data)))
144144
n += copy(buf[n:], data)
145145

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

151154
if !dl.IsZero() {
152-
if err := mp.con.SetWriteDeadline(time.Time{}); err != nil {
153-
return err
155+
// only return this error if we don't *already* have an error from the write.
156+
if err2 := mp.con.SetWriteDeadline(time.Time{}); err == nil && err2 != nil {
157+
return err2
154158
}
155159
}
156160

157-
return nil
161+
return err
158162
}
159163

160164
func (mp *Multiplex) nextChanID() uint64 {

0 commit comments

Comments
 (0)