Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database/sql: a Stmt on a Tx is not safe for concurrent use #20646

Closed
kardianos opened this issue Jun 12, 2017 · 3 comments
Closed

database/sql: a Stmt on a Tx is not safe for concurrent use #20646

kardianos opened this issue Jun 12, 2017 · 3 comments
Assignees
Milestone

Comments

@kardianos
Copy link
Contributor

@kardianos kardianos commented Jun 12, 2017

When fixing #20622 it was necessary to instrument the fakeDB in such a way so race conditions on the driver would become apparent. After fixing that issue and running the trybots, TestConcurrency/TxStmtQuery began failing. This was because this test starts a transaction and then creates a Stmt on the Tx. It then calls stmt.Query in parallel. This results in a potential race condition on the Tx driver connection.

One possible fix is to hold the Stmt.closemu exclusively during queries if Stmt.tx is not null.
The other "fix" is to remove this test case and declare Stmts that derive from Tx should still be called in a single threaded manner.

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 12, 2017

CL https://golang.org/cl/45275 mentions this issue.

@kardianos kardianos self-assigned this Jun 12, 2017
@kardianos kardianos added this to the Go1.9 milestone Jun 12, 2017
@kardianos kardianos added the NeedsFix label Jun 12, 2017
gopherbot pushed a commit that referenced this issue Jun 12, 2017
In addition to adding a guard to the Rows close, add a var
in the fakeConn that gets read and written to on each
operation, simulating writing or reading from the server.

TestConcurrency/TxStmt* tests have been commented out
as they now fail after checking for races on the fakeConn.
See issue #20646 for more information.

Fixes #20622

Change-Id: I80b36ea33d776e5b4968be1683ff8c61728ee1ea
Reviewed-on: https://go-review.googlesource.com/45275
Run-TryBot: Daniel Theophanes <kardianos@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@gopherbot
Copy link

@gopherbot gopherbot commented Jun 12, 2017

CL https://golang.org/cl/45391 mentions this issue.

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 12, 2017

CL https://golang.org/cl/45393 mentions this issue.

@gopherbot gopherbot closed this in 5c37397 Jun 12, 2017
@golang golang locked and limited conversation to collaborators Jun 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.