database/sql: fix double connection free on Stmt.Query error

In a transaction, on a Stmt.Query error, it was possible for a
connection to be added to a db's freelist twice. Should use
the local releaseConn function instead.

Thanks to Gwenael Treguier for the failing test.

Also in this CL: propagate driver errors through releaseConn
into *DB.putConn, which conditionally ignores the freelist
addition if the driver signaled ErrBadConn, introduced in a
previous CL.

R=golang-dev, gary.burd
CC=golang-dev
https://golang.org/cl/5798049
This commit is contained in:
Brad Fitzpatrick 2012-03-10 10:00:02 -08:00
parent 81a38fbb77
commit 3297fc63d6
3 changed files with 58 additions and 9 deletions

View file

@ -209,10 +209,10 @@ func (c *fakeConn) Begin() (driver.Tx, error) {
func (c *fakeConn) Close() error {
if c.currTx != nil {
return errors.New("can't close; in a Transaction")
return errors.New("can't close fakeConn; in a Transaction")
}
if c.db == nil {
return errors.New("can't close; already closed")
return errors.New("can't close fakeConn; already closed")
}
c.db = nil
return nil