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 ( ...@@ -518,12 +518,12 @@ var (
func (db *DB) connIfFree(wanted *driverConn) (*driverConn, error) { func (db *DB) connIfFree(wanted *driverConn) (*driverConn, error) {
db.mu.Lock() db.mu.Lock()
defer db.mu.Unlock() defer db.mu.Unlock()
if wanted.inUse {
return nil, errConnBusy
}
if wanted.dbmuClosed { if wanted.dbmuClosed {
return nil, errConnClosed return nil, errConnClosed
} }
if wanted.inUse {
return nil, errConnBusy
}
for i, conn := range db.freeConn { for i, conn := range db.freeConn {
if conn != wanted { if conn != wanted {
continue continue
...@@ -590,6 +590,7 @@ func (db *DB) putConn(dc *driverConn, err error) { ...@@ -590,6 +590,7 @@ func (db *DB) putConn(dc *driverConn, err error) {
if err == driver.ErrBadConn { if err == driver.ErrBadConn {
// Don't reuse bad connections. // Don't reuse bad connections.
db.mu.Unlock() db.mu.Unlock()
dc.Close()
return return
} }
if putConnHook != nil { if putConnHook != nil {
......
...@@ -1112,7 +1112,6 @@ func manyConcurrentQueries(t testOrBench) { ...@@ -1112,7 +1112,6 @@ func manyConcurrentQueries(t testOrBench) {
} }
func TestIssue6081(t *testing.T) { func TestIssue6081(t *testing.T) {
t.Skip("known broken test")
db := newTestDB(t, "people") db := newTestDB(t, "people")
defer closeDB(t, db) 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