aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/sql_test.go
diff options
context:
space:
mode:
authorDaniel Theophanes <kardianos@gmail.com>2017-06-05 09:04:05 -0700
committerDaniel Theophanes <kardianos@gmail.com>2017-06-05 19:48:49 +0000
commit729685c1d1bbd108f442cbecca6b998689266f60 (patch)
treebee55aa68473d0145c666823ec9b74cc4547abba /src/database/sql/sql_test.go
parenteea8c88a095d4aa21893d96441cb5074a7314532 (diff)
downloadgo-729685c1d1bbd108f442cbecca6b998689266f60.tar.xz
database/sql: ensure Rows is closed when Tx closes
Close any Rows queried within a Tx when the Tx is closed. This prevents the Tx from blocking on rollback if a Rows query has not been closed yet. Fixes #20575 Change-Id: I4efe9c4150e951d8a0f1c40d9d5e325964fdd608 Reviewed-on: https://go-review.googlesource.com/44812 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/database/sql/sql_test.go')
-rw-r--r--src/database/sql/sql_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go
index f5bacc4324..8a477edf1a 100644
--- a/src/database/sql/sql_test.go
+++ b/src/database/sql/sql_test.go
@@ -2467,6 +2467,32 @@ func TestManyErrBadConn(t *testing.T) {
}
}
+// TestIssue20575 ensures the Rows from query does not block
+// closing a transaction. Ensure Rows is closed while closing a trasaction.
+func TestIssue20575(t *testing.T) {
+ db := newTestDB(t, "people")
+ tx, err := db.Begin()
+ if err != nil {
+ t.Fatal(err)
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
+ defer cancel()
+ _, err = tx.QueryContext(ctx, "SELECT|people|age,name|")
+ if err != nil {
+ t.Fatal(err)
+ }
+ // Do not close Rows from QueryContext.
+ err = tx.Rollback()
+ if err != nil {
+ t.Fatal(err)
+ }
+ select {
+ default:
+ case <-ctx.Done():
+ t.Fatal("timeout: failed to rollback query without closing rows:", ctx.Err())
+ }
+}
+
// golang.org/issue/5718
func TestErrBadConnReconnect(t *testing.T) {
db := newTestDB(t, "foo")