Commit 292366e7 authored by Daniel Theophanes's avatar Daniel Theophanes

Revert "database/sql: prevent race in driver by locking dc in Next"

This reverts commit 897080d5.

Reason for revert: Fails to fix all the locking issues.

Updates #21117

Change-Id: I6fc9cb7897244d6e1af78c089a2bf383258ec049
Reviewed-on: https://go-review.googlesource.com/71450Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 94e3a304
...@@ -943,7 +943,6 @@ type rowsCursor struct { ...@@ -943,7 +943,6 @@ type rowsCursor struct {
} }
func (rc *rowsCursor) touchMem() { func (rc *rowsCursor) touchMem() {
rc.parentMem.touchMem()
rc.line++ rc.line++
} }
......
...@@ -2491,12 +2491,6 @@ func (rs *Rows) nextLocked() (doClose, ok bool) { ...@@ -2491,12 +2491,6 @@ func (rs *Rows) nextLocked() (doClose, ok bool) {
if rs.lastcols == nil { if rs.lastcols == nil {
rs.lastcols = make([]driver.Value, len(rs.rowsi.Columns())) rs.lastcols = make([]driver.Value, len(rs.rowsi.Columns()))
} }
// Lock the driver connection before calling the driver interface
// rowsi to prevent a Tx from rolling back the connection at the same time.
rs.dc.Lock()
defer rs.dc.Unlock()
rs.lasterr = rs.rowsi.Next(rs.lastcols) rs.lasterr = rs.rowsi.Next(rs.lastcols)
if rs.lasterr != nil { if rs.lasterr != nil {
// Close the connection if there is a driver error. // Close the connection if there is a driver error.
...@@ -2546,12 +2540,6 @@ func (rs *Rows) NextResultSet() bool { ...@@ -2546,12 +2540,6 @@ func (rs *Rows) NextResultSet() bool {
doClose = true doClose = true
return false return false
} }
// Lock the driver connection before calling the driver interface
// rowsi to prevent a Tx from rolling back the connection at the same time.
rs.dc.Lock()
defer rs.dc.Unlock()
rs.lasterr = nextResultSet.NextResultSet() rs.lasterr = nextResultSet.NextResultSet()
if rs.lasterr != nil { if rs.lasterr != nil {
doClose = true doClose = true
......
...@@ -3127,9 +3127,6 @@ func TestIssue6081(t *testing.T) { ...@@ -3127,9 +3127,6 @@ func TestIssue6081(t *testing.T) {
// In the test, a context is canceled while the query is in process so // In the test, a context is canceled while the query is in process so
// the internal rollback will run concurrently with the explicitly called // the internal rollback will run concurrently with the explicitly called
// Tx.Rollback. // Tx.Rollback.
//
// The addition of calling rows.Next also tests
// Issue 21117.
func TestIssue18429(t *testing.T) { func TestIssue18429(t *testing.T) {
db := newTestDB(t, "people") db := newTestDB(t, "people")
defer closeDB(t, db) defer closeDB(t, db)
...@@ -3140,7 +3137,7 @@ func TestIssue18429(t *testing.T) { ...@@ -3140,7 +3137,7 @@ func TestIssue18429(t *testing.T) {
const milliWait = 30 const milliWait = 30
for i := 0; i < 1000; i++ { for i := 0; i < 100; i++ {
sem <- true sem <- true
wg.Add(1) wg.Add(1)
go func() { go func() {
...@@ -3162,9 +3159,6 @@ func TestIssue18429(t *testing.T) { ...@@ -3162,9 +3159,6 @@ func TestIssue18429(t *testing.T) {
// reported. // reported.
rows, _ := tx.QueryContext(ctx, "WAIT|"+qwait+"|SELECT|people|name|") rows, _ := tx.QueryContext(ctx, "WAIT|"+qwait+"|SELECT|people|name|")
if rows != nil { if rows != nil {
// Call Next to test Issue 21117 and check for races.
for rows.Next() {
}
rows.Close() rows.Close()
} }
// This call will race with the context cancel rollback to complete // This call will race with the context cancel rollback to complete
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment