mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
database/sql: ensure all driver interfaces are called under single lock
Russ pointed out in a previous CL golang.org/cl/65731 that not only was the locking incomplete, previous changes did not correctly lock driver calls in other sections. After inspecting driverConn, driverStmt, driverResult, Tx, and Rows structs where driver interfaces are stored, I discovered a few more places that failed to lock driver calls. The largest of these was the parameter type converter "driverArgs". driverArgs was typically called right before another call to the driver in a locked region, so I made the entire driverArgs expect a locked driver mutex and combined the region. This should not be a problem because the connection is pulled out of the connection pool either way so there shouldn't be contention. Fixes #21117 Change-Id: I88d46f74dca25fb11a30f0bf8e79785a73133d23 Reviewed-on: https://go-review.googlesource.com/71433 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
986582126a
commit
1126d1483f
5 changed files with 55 additions and 39 deletions
|
|
@ -3157,6 +3157,9 @@ func TestIssue6081(t *testing.T) {
|
|||
// In the test, a context is canceled while the query is in process so
|
||||
// the internal rollback will run concurrently with the explicitly called
|
||||
// Tx.Rollback.
|
||||
//
|
||||
// The addition of calling rows.Next also tests
|
||||
// Issue 21117.
|
||||
func TestIssue18429(t *testing.T) {
|
||||
db := newTestDB(t, "people")
|
||||
defer closeDB(t, db)
|
||||
|
|
@ -3189,6 +3192,9 @@ func TestIssue18429(t *testing.T) {
|
|||
// reported.
|
||||
rows, _ := tx.QueryContext(ctx, "WAIT|"+qwait+"|SELECT|people|name|")
|
||||
if rows != nil {
|
||||
// Call Next to test Issue 21117 and check for races.
|
||||
for rows.Next() {
|
||||
}
|
||||
rows.Close()
|
||||
}
|
||||
// This call will race with the context cancel rollback to complete
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue