mirror of
https://github.com/golang/go
synced 2024-11-19 22:44:45 -07:00
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
This commit is contained in:
parent
97aa90d251
commit
ce6b75dab6
@ -652,13 +652,16 @@ func (db *DB) conn() (*driverConn, error) {
|
|||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db.numOpen++ // optimistically
|
||||||
db.mu.Unlock()
|
db.mu.Unlock()
|
||||||
ci, err := db.driver.Open(db.dsn)
|
ci, err := db.driver.Open(db.dsn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
db.mu.Lock()
|
||||||
|
db.numOpen-- // correct for earlier optimism
|
||||||
|
db.mu.Unlock()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
db.mu.Lock()
|
db.mu.Lock()
|
||||||
db.numOpen++
|
|
||||||
dc := &driverConn{
|
dc := &driverConn{
|
||||||
db: db,
|
db: db,
|
||||||
ci: ci,
|
ci: ci,
|
||||||
|
Loading…
Reference in New Issue
Block a user