mirror of
https://github.com/golang/go
synced 2024-11-19 20:54:39 -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
|
||||
}
|
||||
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user