Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: server idleTimeout documentation issue #20383

Closed
prabrisat1 opened this issue May 16, 2017 · 1 comment
Closed

net/http: server idleTimeout documentation issue #20383

prabrisat1 opened this issue May 16, 2017 · 1 comment
Labels
Documentation FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@prabrisat1
Copy link

What version of Go are you using (go version)?

go version go1.8 darwin/amd64

What operating system and processor architecture are you using (go env)?

not really relevant but listed below:
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/puvvadip/Documents/work"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4r/1g2c4css78b1yn2q32dmqqm0l05w9h/T/go-build790682604=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

Issue

net/http's server documentation states

 // IdleTimeout is the maximum amount of time to wait for the
 // next request when keep-alives are enabled. If IdleTimeout
 // is zero, the value of ReadTimeout is used. If both are
 // zero, there is no timeout.
 IdleTimeout time.Duration

However, if no conn ReadDeadline is set because idleTimeout is zero at the bottom of the main loop of net/http.(*conn).serve (the relevant code is below)

    if d := c.server.idleTimeout(); d != 0 {
        c.rwc.SetReadDeadline(time.Now().Add(d))
        if _, err := c.bufr.Peek(4); err != nil {
            return
        }
    }
    c.rwc.SetReadDeadline(time.Time{})

Then the next iteration of the loop starts with

   w, err := c.readRequest(ctx)

Which starts with

  func (c *conn) readRequest(ctx context.Context) (w *response, err error) {
  	if c.hijacked() {
  		return nil, ErrHijacked
  	}
  
  	var (
  		wholeReqDeadline time.Time // or zero if none
  		hdrDeadline      time.Time // or zero if none
  	)
  	t0 := time.Now()
  	if d := c.server.readHeaderTimeout(); d != 0 {
  		hdrDeadline = t0.Add(d)
  	}
  	if d := c.server.ReadTimeout; d != 0 {
  		wholeReqDeadline = t0.Add(d)
  	}
  	c.rwc.SetReadDeadline(hdrDeadline)

Therefore in the case where both idleTimeout and readTimeout are not set, the readHeaderTimeout is used. The documentation for idleTimeout should state, “If both are zero, ReadHeaderTimeout is used.”

@bradfitz bradfitz changed the title net/http server idleTimeout documentation issue net/http: server idleTimeout documentation issue May 16, 2017
@bradfitz bradfitz added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 16, 2017
@bradfitz bradfitz added this to the Go1.9 milestone May 16, 2017
@gopherbot
Copy link

CL https://golang.org/cl/46434 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants