mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
database/sql: fix accumulation of bad conns on prepared statements
Fixes an issue where prepared statements that outlive many connections become expensive to invoke. Fixes #6081 R=golang-dev CC=bradfitz, golang-dev https://golang.org/cl/12646044
This commit is contained in:
parent
e0ca536f36
commit
13c7896fb6
2 changed files with 4 additions and 4 deletions
|
|
@ -518,12 +518,12 @@ var (
|
|||
func (db *DB) connIfFree(wanted *driverConn) (*driverConn, error) {
|
||||
db.mu.Lock()
|
||||
defer db.mu.Unlock()
|
||||
if wanted.inUse {
|
||||
return nil, errConnBusy
|
||||
}
|
||||
if wanted.dbmuClosed {
|
||||
return nil, errConnClosed
|
||||
}
|
||||
if wanted.inUse {
|
||||
return nil, errConnBusy
|
||||
}
|
||||
for i, conn := range db.freeConn {
|
||||
if conn != wanted {
|
||||
continue
|
||||
|
|
@ -590,6 +590,7 @@ func (db *DB) putConn(dc *driverConn, err error) {
|
|||
if err == driver.ErrBadConn {
|
||||
// Don't reuse bad connections.
|
||||
db.mu.Unlock()
|
||||
dc.Close()
|
||||
return
|
||||
}
|
||||
if putConnHook != nil {
|
||||
|
|
|
|||
|
|
@ -1112,7 +1112,6 @@ func manyConcurrentQueries(t testOrBench) {
|
|||
}
|
||||
|
||||
func TestIssue6081(t *testing.T) {
|
||||
t.Skip("known broken test")
|
||||
db := newTestDB(t, "people")
|
||||
defer closeDB(t, db)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue