Skip to content

Commit a6e0f74

Browse files
committed
Problem: NetConn wrapper kept canceling context
Solution: Accept the zero time as a special case when setting deadlines. Somehow, this function gets called without a time and thus would previously Reset the timer to no time at all, thus expediting the call to cancel the context.
1 parent 3e63f82 commit a6e0f74

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

netconn.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,23 @@ func (c *netConn) SetDeadline(t time.Time) error {
134134
}
135135

136136
func (c *netConn) SetWriteDeadline(t time.Time) error {
137-
c.writeTimer.Reset(t.Sub(time.Now()))
137+
if t.IsZero() {
138+
if !c.writeTimer.Stop() {
139+
<-c.writeTimer.C
140+
}
141+
} else {
142+
c.writeTimer.Reset(t.Sub(time.Now()))
143+
}
138144
return nil
139145
}
140146

141147
func (c *netConn) SetReadDeadline(t time.Time) error {
142-
c.readTimer.Reset(t.Sub(time.Now()))
148+
if t.IsZero() {
149+
if !c.readTimer.Stop() {
150+
<-c.readTimer.C
151+
}
152+
} else {
153+
c.readTimer.Reset(t.Sub(time.Now()))
154+
}
143155
return nil
144156
}

0 commit comments

Comments
 (0)