Skip to content

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

Open
@ahajunzi

Description

@ahajunzi

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:[email protected]'
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions