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

database/sql: SetConnMaxIdleTime, SetConnMaxLifetime order impacts close time #45993

Open
eqinox76 opened this issue May 6, 2021 · 3 comments
Open

Comments

@eqinox76
Copy link

@eqinox76 eqinox76 commented May 6, 2021

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.

@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented May 6, 2021

@Equinox76 both lines look the same?

@eqinox76
Copy link
Author

@eqinox76 eqinox76 commented May 6, 2021

Thanks! Copy paste error which i corrected.

@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented May 8, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants