Skip to content

Commit f08c552

Browse files
jharshmanodeke-em
authored andcommitted
net/http: add to deadlines only when positive
The existing implementation allows read / write deadlines to exist in the past. This updates conditionals to only add to the deadline when the value is positive. Fixes: #39177 Change-Id: I841c30ba2849a337e7bc98c8aa136c4527c314ed Reviewed-on: https://go-review.googlesource.com/c/go/+/235437 Reviewed-by: Emmanuel Odeke <[email protected]> Reviewed-by: Damien Neil <[email protected]> Run-TryBot: Emmanuel Odeke <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Damien Neil <[email protected]>
1 parent bdddfd1 commit f08c552

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/net/http/server.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -964,14 +964,14 @@ func (c *conn) readRequest(ctx context.Context) (w *response, err error) {
964964
hdrDeadline time.Time // or zero if none
965965
)
966966
t0 := time.Now()
967-
if d := c.server.readHeaderTimeout(); d != 0 {
967+
if d := c.server.readHeaderTimeout(); d > 0 {
968968
hdrDeadline = t0.Add(d)
969969
}
970-
if d := c.server.ReadTimeout; d != 0 {
970+
if d := c.server.ReadTimeout; d > 0 {
971971
wholeReqDeadline = t0.Add(d)
972972
}
973973
c.rwc.SetReadDeadline(hdrDeadline)
974-
if d := c.server.WriteTimeout; d != 0 {
974+
if d := c.server.WriteTimeout; d > 0 {
975975
defer func() {
976976
c.rwc.SetWriteDeadline(time.Now().Add(d))
977977
}()
@@ -1831,10 +1831,10 @@ func (c *conn) serve(ctx context.Context) {
18311831
}()
18321832

18331833
if tlsConn, ok := c.rwc.(*tls.Conn); ok {
1834-
if d := c.server.ReadTimeout; d != 0 {
1834+
if d := c.server.ReadTimeout; d > 0 {
18351835
c.rwc.SetReadDeadline(time.Now().Add(d))
18361836
}
1837-
if d := c.server.WriteTimeout; d != 0 {
1837+
if d := c.server.WriteTimeout; d > 0 {
18381838
c.rwc.SetWriteDeadline(time.Now().Add(d))
18391839
}
18401840
if err := tlsConn.HandshakeContext(ctx); err != nil {
@@ -2567,7 +2567,8 @@ type Server struct {
25672567
TLSConfig *tls.Config
25682568

25692569
// ReadTimeout is the maximum duration for reading the entire
2570-
// request, including the body.
2570+
// request, including the body. A zero or negative value means
2571+
// there will be no timeout.
25712572
//
25722573
// Because ReadTimeout does not let Handlers make per-request
25732574
// decisions on each request body's acceptable deadline or
@@ -2587,6 +2588,7 @@ type Server struct {
25872588
// writes of the response. It is reset whenever a new
25882589
// request's header is read. Like ReadTimeout, it does not
25892590
// let Handlers make decisions on a per-request basis.
2591+
// A zero or negative value means there will be no timeout.
25902592
WriteTimeout time.Duration
25912593

25922594
// IdleTimeout is the maximum amount of time to wait for the

0 commit comments

Comments
 (0)