Skip to content

Commit 7346d20

Browse files
committed
net/http: fix zombie connection leaked
When `Server.IdleTimeout` is not zero and after the first request, the client sends part of the data of a full request, and the data is no less than 4 bytes, the idle timeout which has been set will be reset to zero here and would never close the conn: https://github.com/golang/go/blob/master/src/net/http/server.go#L1996
1 parent c1f2213 commit 7346d20

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/net/http/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,9 @@ func (c *conn) readRequest(ctx context.Context) (w *response, err error) {
968968
t0 := time.Now()
969969
if d := c.server.readHeaderTimeout(); d > 0 {
970970
hdrDeadline = t0.Add(d)
971+
} else {
972+
const headerTimeout = 30 * time.Second
973+
hdrDeadline = t0.Add(headerTimeout)
971974
}
972975
if d := c.server.ReadTimeout; d > 0 {
973976
wholeReqDeadline = t0.Add(d)
@@ -1993,7 +1996,6 @@ func (c *conn) serve(ctx context.Context) {
19931996
return
19941997
}
19951998
}
1996-
c.rwc.SetReadDeadline(time.Time{})
19971999
}
19982000
}
19992001

0 commit comments

Comments
 (0)