Commit 13c7896f authored by Matt Joiner's avatar Matt Joiner Committed by Brad Fitzpatrick

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
parent e0ca536f
......@@ -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)
......
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