Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.16.3 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/carsten/.cache/go-build" GOENV="/home/carsten/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/carsten/go/pkg/mod" GONOPROXY="dev.azure.com/xtp" GONOSUMDB="dev.azure.com/xtp" GOOS="linux" GOPATH="/home/carsten/go" GOPROXY="https://proxy.golang.org,direct" GOROOT="/snap/go/7360" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/snap/go/7360/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.16.3" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3305456222=/tmp/go-build -gno-record-gcc-switches" GOROOT/bin/go version: go version go1.16.3 linux/amd64 GOROOT/bin/go tool compile -V: compile version go1.16.3 uname -sr: Linux 5.8.0-50-generic Distributor ID: Ubuntu Description: Ubuntu 20.04.2 LTS Release: 20.04 Codename: focal /lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.31-0ubuntu9.2) stable release version 2.31. gdb --version: GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
What did you do?
When using
db.SetConnMaxIdleTime(5 * time.Second)
db.SetConnMaxLifetime(5 * time.Hour)
idle connections get closed after 5 hours. While setting the parameters in reverse order works fine.
db.SetConnMaxLifetime(5 * time.Hour)
db.SetConnMaxIdleTime(5 * time.Second)
What did you expect to see?
Closing idle connections after ~5s.
What did you see instead?
Closing connections after ~5h
I think this is due to sql.go#L1041 only checking if maxIdleTime
has been reduced and not also if its smaller than maxLifetime
.