1
0
mirror of https://github.com/golang/go synced 2024-11-18 09:04:49 -07:00

database/sql: stop reuse of bad connections

The second parameter for sql.putConn() (err) is always nil. As a result bad
connections are reused, even if the driver returns an driver.ErrBadConn.
Unsing a pointer to err instead achievs the desired behavior.
See http://code.google.com/p/go/issues/detail?id=3777 for more details.
Fixes #3777.

R=golang-dev, dave, bradfitz, jameshuachow, BlakeSGentry
CC=golang-dev
https://golang.org/cl/6348069
This commit is contained in:
Julien Schmidt 2012-08-23 19:29:47 -07:00 committed by Brad Fitzpatrick
parent c39509a3b3
commit 37b40dab51

9
src/pkg/database/sql/sql.go Normal file → Executable file
View File

@ -311,7 +311,10 @@ func (db *DB) prepare(query string) (stmt *Stmt, err error) {
if err != nil {
return nil, err
}
defer db.putConn(ci, err)
defer func() {
db.putConn(ci, err)
}()
si, err := ci.Prepare(query)
if err != nil {
return nil, err
@ -342,7 +345,9 @@ func (db *DB) exec(query string, args []interface{}) (res Result, err error) {
if err != nil {
return nil, err
}
defer db.putConn(ci, err)
defer func() {
db.putConn(ci, err)
}()
if execer, ok := ci.(driver.Execer); ok {
dargs, err := driverArgs(nil, args)