golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.67k stars 17.62k forks source link

net/http: IdleConnTimeout is invalid for HTTP/2 #69205

Open ahajunzi opened 1 month ago

ahajunzi commented 1 month ago

Go version

go version go1.22.2 linux/amd64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/data/home/sakiluzhang/.cache/go-build'
GOENV='/data/home/sakiluzhang/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/data/home/sakiluzhang/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/data/home/sakiluzhang/go'
GOPRIVATE=''
GOPROXY='https://sakiluzhang:lFEajkXQ@goproxy.woa.com'
GOROOT='/data/home/sakiluzhang/go'
GOSUMDB='sum.woa.com+643d7a06+Ac5f5VOC4N8NUXdmhbm8pZSXIWfhek5JSmWdWrq7pLX4'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/data/home/sakiluzhang/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/data/home/sakiluzhang/DServer/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build929430334=/tmp/go-build -gno-record-gcc-switches'

What did you do?

func (t *Transport) tryPutIdleConn(pconn *persistConn) error {

    if t.DisableKeepAlives || t.MaxIdleConnsPerHost < 0 {
        return errKeepAlivesDisabled
    }
    if pconn.isBroken() {
        return errConnBroken
    }
    pconn.markReused()

    t.idleMu.Lock()
    defer t.idleMu.Unlock()

    // HTTP/2 (pconn.alt != nil) connections do not come out of the idle list,
    // because multiple goroutines can use them simultaneously.
    // If this is an HTTP/2 connection being “returned,” we're done.
    if pconn.alt != nil && t.idleLRU.m[pconn] != nil {
             **here pconn.idleAt has not been updated and returned.**
        return nil
    }
       ......

What did you see happen?

I hope one connection is checked IdleConnTimeout should start at the latest time I used it rather than the first time

I hope *http.Transport.idleLRU list should remove connection not only by MaxIdleConns (in many cases, you can't estimate proper num for in China there maybe Tens of millions users use our product simultaneously and more http requests will be produced) but also by IdleConnTimeout

What did you expect to see?

read above

gabyhelp commented 1 month ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

ianlancetaylor commented 1 month ago

CC @neild

neild commented 1 month ago

The HTTP/2 idle timeout is handled in the HTTP/2 transport: https://go.googlesource.com/net/+/refs/tags/v0.28.0/http2/transport.go#862