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
Milestone

Comments

@colinking
Copy link
Contributor

@colinking colinking commented Mar 25, 2020

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 this to the Unplanned milestone Mar 25, 2020
@kardianos
Copy link
Contributor

@kardianos kardianos commented Mar 25, 2020

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.

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 22, 2020

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

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.

4 participants
You can’t perform that action at this time.