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: incorrect count for DBStats.MaxLifetimeClosed for connections not closed in background goroutine #38058

Closed
colinking opened this issue Mar 25, 2020 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@colinking
Copy link
Contributor

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

$ go version
go version go1.13.8 darwin/amd64

Does this issue reproduce with the latest release?

Based on the latest master, yeah.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/colinking/Library/Caches/go-build"
GOENV="/Users/colinking/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY="github.com/segment*"
GONOSUMDB="github.com/segment*"
GOOS="darwin"
GOPATH="/Users/colinking/dev"
GOPRIVATE="github.com/segment*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.8/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.8/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/colinking/dev/src/github.com/segmentio/cell-ctlstore/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/p6/62gms5fd2sd51_yf9qzbrs9c0000gn/T/go-build662696632=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

We were tracking the number of closed connections over the lifetime of a process with MaxLifetimeClosed from DBStats after setting a max connection lifetime with SetConnMaxLifetime.

What did you expect to see?

We expected MaxLifetimeClosed to be incremented once for every connection that was closed due to SetConnMaxLifetime.

What did you see instead?

Only connections closed via the background goroutine (connectionCleaner) were counted. Connections that are closed in conn (here and here) because it determines they are expired (and currently free) were not counted.

If this is the expected behavior, then I'm happy to open a PR with a fix.

@colinking colinking changed the title [database/sql] MaxLifetimeConnections [database/sql] Incorrect count for DBStats.MaxLifetimeClosed Mar 25, 2020
@odeke-em odeke-em changed the title [database/sql] Incorrect count for DBStats.MaxLifetimeClosed database/sql: incorrect count for DBStats.MaxLifetimeClosed for connections not closed in background goroutine Mar 25, 2020
@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 25, 2020
@andybons andybons added this to the Unplanned milestone Mar 25, 2020
@andybons
Copy link
Member

@kardianos
Copy link
Contributor

Yes, I believe you are correct. Those are closed due to max lifetime, but are not recorded in Stats.

Please keep this CL in mind if you send a patch.

@kardianos kardianos added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 25, 2020
colinking added a commit to colinking/go that referenced this issue Apr 5, 2020
@gopherbot
Copy link

Change https://golang.org/cl/227278 mentions this issue: database/sql: count connections expired in foreground with MaxLifetimeClosed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants