Description
What version of Go are you using (go version
)?
Both Go 1.11 and the current tip. MaxIdleClosed is not available in Go 1.10.
What did you do?
// use single database connection, never close it, always reuse
db.SetMaxOpenConns(1)
db.SetMaxIdleConns(1)
db.SetConnMaxLifetime(0)
log.Printf("%+v", db.Stats())
for i := 0; i < 10; i++ {
if _, err := db.Exec("SELECT 1"); err != nil {
log.Fatal(err)
}
}
log.Printf("%+v", db.Stats())
https://github.com/AlekSi/go-sql-bugs/blob/master/issue27792_test.go
What did you expect to see?
{MaxOpenConnections:1 OpenConnections:0 InUse:0 Idle:0 WaitCount:0 WaitDuration:0s MaxIdleClosed:0 MaxLifetimeClosed:0}
{MaxOpenConnections:1 OpenConnections:1 InUse:0 Idle:1 WaitCount:0 WaitDuration:0s MaxIdleClosed:0 MaxLifetimeClosed:0}
What did you see instead?
{MaxOpenConnections:1 OpenConnections:0 InUse:0 Idle:0 WaitCount:0 WaitDuration:0s MaxIdleClosed:0 MaxLifetimeClosed:0}
{MaxOpenConnections:1 OpenConnections:1 InUse:0 Idle:1 WaitCount:0 WaitDuration:0s MaxIdleClosed:10 MaxLifetimeClosed:0}
By patching a driver I noticed that only a single connection is established in fact. But the statistic is wrong.
/cc @kardianos