mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
database/sql: close bad connections in commit or rollback:
Previously Tx.close always passed a nil error to tx.db.putConn. As a result bad connections were reused, even if the driver returned driver.ErrBadConn. Adding an err parameter to Tx.close allows it to receive the driver error from Tx.Commit and Tx.Rollback and pass it to tx.db.putConn. Fixes #11264 Change-Id: I142b6b2509fa8d714bbc135cef7281a40803b3b8 Reviewed-on: https://go-review.googlesource.com/13912 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
bf99d8f843
commit
d737639c4a
3 changed files with 87 additions and 4 deletions
|
|
@ -699,13 +699,25 @@ func (s *fakeStmt) NumInput() int {
|
|||
return s.placeholders
|
||||
}
|
||||
|
||||
// hook to simulate broken connections
|
||||
var hookCommitBadConn func() bool
|
||||
|
||||
func (tx *fakeTx) Commit() error {
|
||||
tx.c.currTx = nil
|
||||
if hookCommitBadConn != nil && hookCommitBadConn() {
|
||||
return driver.ErrBadConn
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// hook to simulate broken connections
|
||||
var hookRollbackBadConn func() bool
|
||||
|
||||
func (tx *fakeTx) Rollback() error {
|
||||
tx.c.currTx = nil
|
||||
if hookRollbackBadConn != nil && hookRollbackBadConn() {
|
||||
return driver.ErrBadConn
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue