mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
81a38fbb77
commit
3297fc63d6
3 changed files with 58 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue