Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
database/sql: a Stmt on a Tx is not safe for concurrent use #20646
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.
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 <firstname.lastname@example.org> TryBot-Result: Gobot Gobot <email@example.com> Reviewed-by: Brad Fitzpatrick <firstname.lastname@example.org>