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>
diff --git a/src/database/sql/fakedb_test.go b/src/database/sql/fakedb_test.go
index 8cbbb29..112f280e 100644
--- a/src/database/sql/fakedb_test.go
+++ b/src/database/sql/fakedb_test.go
@@ -699,13 +699,25 @@
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
}