]> Cypherpunks.ru repositories - gostls13.git/commit
[release-branch.go1.9] database/sql: prevent race in driver by locking dc in Next
authorDaniel Theophanes <kardianos@gmail.com>
Sat, 23 Sep 2017 22:30:46 +0000 (15:30 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 25 Oct 2017 20:23:34 +0000 (20:23 +0000)
commitfd17253587862248ee9a30a89e59db2fa9b77d1d
treee7f311d900cfb121ecc3dd764e389ea2509ad284
parent7e7cb30475d69bfbaaa8c7519c551f9bd243a756
[release-branch.go1.9] database/sql: prevent race in driver by locking dc in Next

Database drivers should be called from a single goroutine to ease
driver's design. If a driver chooses to handle context
cancels internally it may do so.

The sql package violated this agreement when calling Next or
NextResultSet. It was possible for a concurrent rollback
triggered from a context cancel to call a Tx.Rollback (which
takes a driver connection lock) while a Rows.Next is in progress
(which does not tack the driver connection lock).

The current internal design of the sql package is each call takes
roughly two locks: a closemu lock which prevents an disposing of
internal resources (assigning nil or removing from lists)
and a driver connection lock that prevents calling driver code from
multiple goroutines.

Fixes #21117

Change-Id: Ie340dc752a503089c27f57ffd43e191534829360
Reviewed-on: https://go-review.googlesource.com/65731
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-on: https://go-review.googlesource.com/71510
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
src/database/sql/fakedb_test.go
src/database/sql/sql.go
src/database/sql/sql_test.go