Commit ce6b75da authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

database/sql: fix accounting of open connections

Existing test TestMaxOpenConns was failing occasionally, especially
with higher values of GOMAXPROCS.

Fixes #7532

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/95130043
parent 97aa90d2
......@@ -652,13 +652,16 @@ func (db *DB) conn() (*driverConn, error) {
return conn, nil
}
db.numOpen++ // optimistically
db.mu.Unlock()
ci, err := db.driver.Open(db.dsn)
if err != nil {
db.mu.Lock()
db.numOpen-- // correct for earlier optimism
db.mu.Unlock()
return nil, err
}
db.mu.Lock()
db.numOpen++
dc := &driverConn{
db: db,
ci: ci,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment