]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: add to deadlines only when positive
authorJoshua Harshman <joshgreyhat@gmail.com>
Wed, 27 May 2020 15:54:41 +0000 (09:54 -0600)
committerEmmanuel Odeke <emmanuel@orijtech.com>
Fri, 16 Apr 2021 01:54:27 +0000 (01:54 +0000)
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 <emmanuel@orijtech.com>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Damien Neil <dneil@google.com>

src/net/http/server.go

index f095b7edd270133641ebe143b2278ae56d5e2cd9..d90418b56dd272469fae16cd54878f3b1b008f61 100644 (file)
@@ -964,14 +964,14 @@ func (c *conn) readRequest(ctx context.Context) (w *response, err error) {
                hdrDeadline      time.Time // or zero if none
        )
        t0 := time.Now()
-       if d := c.server.readHeaderTimeout(); d != 0 {
+       if d := c.server.readHeaderTimeout(); d > 0 {
                hdrDeadline = t0.Add(d)
        }
-       if d := c.server.ReadTimeout; d != 0 {
+       if d := c.server.ReadTimeout; d > 0 {
                wholeReqDeadline = t0.Add(d)
        }
        c.rwc.SetReadDeadline(hdrDeadline)
-       if d := c.server.WriteTimeout; d != 0 {
+       if d := c.server.WriteTimeout; d > 0 {
                defer func() {
                        c.rwc.SetWriteDeadline(time.Now().Add(d))
                }()
@@ -1831,10 +1831,10 @@ func (c *conn) serve(ctx context.Context) {
        }()
 
        if tlsConn, ok := c.rwc.(*tls.Conn); ok {
-               if d := c.server.ReadTimeout; d != 0 {
+               if d := c.server.ReadTimeout; d > 0 {
                        c.rwc.SetReadDeadline(time.Now().Add(d))
                }
-               if d := c.server.WriteTimeout; d != 0 {
+               if d := c.server.WriteTimeout; d > 0 {
                        c.rwc.SetWriteDeadline(time.Now().Add(d))
                }
                if err := tlsConn.HandshakeContext(ctx); err != nil {
@@ -2567,7 +2567,8 @@ type Server struct {
        TLSConfig *tls.Config
 
        // ReadTimeout is the maximum duration for reading the entire
-       // request, including the body.
+       // request, including the body. A zero or negative value means
+       // there will be no timeout.
        //
        // Because ReadTimeout does not let Handlers make per-request
        // decisions on each request body's acceptable deadline or
@@ -2587,6 +2588,7 @@ type Server struct {
        // writes of the response. It is reset whenever a new
        // request's header is read. Like ReadTimeout, it does not
        // let Handlers make decisions on a per-request basis.
+       // A zero or negative value means there will be no timeout.
        WriteTimeout time.Duration
 
        // IdleTimeout is the maximum amount of time to wait for the