Skip to content

Commit 292366e

Browse files
committed
Revert "database/sql: prevent race in driver by locking dc in Next"
This reverts commit 897080d. Reason for revert: Fails to fix all the locking issues. Updates #21117 Change-Id: I6fc9cb7897244d6e1af78c089a2bf383258ec049 Reviewed-on: https://go-review.googlesource.com/71450 Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent 94e3a30 commit 292366e

File tree

3 files changed

+1
-20
lines changed

3 files changed

+1
-20
lines changed

src/database/sql/fakedb_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,6 @@ type rowsCursor struct {
943943
}
944944

945945
func (rc *rowsCursor) touchMem() {
946-
rc.parentMem.touchMem()
947946
rc.line++
948947
}
949948

src/database/sql/sql.go

-12
Original file line numberDiff line numberDiff line change
@@ -2491,12 +2491,6 @@ func (rs *Rows) nextLocked() (doClose, ok bool) {
24912491
if rs.lastcols == nil {
24922492
rs.lastcols = make([]driver.Value, len(rs.rowsi.Columns()))
24932493
}
2494-
2495-
// Lock the driver connection before calling the driver interface
2496-
// rowsi to prevent a Tx from rolling back the connection at the same time.
2497-
rs.dc.Lock()
2498-
defer rs.dc.Unlock()
2499-
25002494
rs.lasterr = rs.rowsi.Next(rs.lastcols)
25012495
if rs.lasterr != nil {
25022496
// Close the connection if there is a driver error.
@@ -2546,12 +2540,6 @@ func (rs *Rows) NextResultSet() bool {
25462540
doClose = true
25472541
return false
25482542
}
2549-
2550-
// Lock the driver connection before calling the driver interface
2551-
// rowsi to prevent a Tx from rolling back the connection at the same time.
2552-
rs.dc.Lock()
2553-
defer rs.dc.Unlock()
2554-
25552543
rs.lasterr = nextResultSet.NextResultSet()
25562544
if rs.lasterr != nil {
25572545
doClose = true

src/database/sql/sql_test.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -3127,9 +3127,6 @@ func TestIssue6081(t *testing.T) {
31273127
// In the test, a context is canceled while the query is in process so
31283128
// the internal rollback will run concurrently with the explicitly called
31293129
// Tx.Rollback.
3130-
//
3131-
// The addition of calling rows.Next also tests
3132-
// Issue 21117.
31333130
func TestIssue18429(t *testing.T) {
31343131
db := newTestDB(t, "people")
31353132
defer closeDB(t, db)
@@ -3140,7 +3137,7 @@ func TestIssue18429(t *testing.T) {
31403137

31413138
const milliWait = 30
31423139

3143-
for i := 0; i < 1000; i++ {
3140+
for i := 0; i < 100; i++ {
31443141
sem <- true
31453142
wg.Add(1)
31463143
go func() {
@@ -3162,9 +3159,6 @@ func TestIssue18429(t *testing.T) {
31623159
// reported.
31633160
rows, _ := tx.QueryContext(ctx, "WAIT|"+qwait+"|SELECT|people|name|")
31643161
if rows != nil {
3165-
// Call Next to test Issue 21117 and check for races.
3166-
for rows.Next() {
3167-
}
31683162
rows.Close()
31693163
}
31703164
// This call will race with the context cancel rollback to complete

0 commit comments

Comments
 (0)