go/src/database/sql
Emmanuel T Odeke c77418f4ca [release-branch.go1.15] database/sql: fix tx stmt deadlock when rollback
Tx acquires tx.closemu W-lock and then acquires stmt.closemu.W-lock
to fully close the transaction and associated prepared statement.
Stmt query and execution run in reverse ways - acquires
stmt.closemu.R-lock and then acquires tx.closemu.R-lock to grab tx
connection, which may cause deadlock.

Prevent the lock is held around tx.closePrepared to ensure no
deadlock happens.

Includes a test fix from CL 266097.
Fixes #42884
Updates #40985
Updates #42259

Change-Id: Id52737660ada3cebdfff6efc23366cdc3224b8e8
Reviewed-on: https://go-review.googlesource.com/c/go/+/250178
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
(cherry picked from commit d4c1ad8829)
Reviewed-on: https://go-review.googlesource.com/c/go/+/284513
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2021-03-30 21:41:42 +00:00
..
driver database/sql/driver: use correct method name "Connect" in DriverContext docs 2020-05-30 03:20:54 +00:00
convert.go all: fix typos 2019-09-08 17:28:20 +00:00
convert_test.go all: fix typos 2019-09-08 17:28:20 +00:00
ctxutil.go std: remove unused bits of code all over the place 2019-09-02 12:57:37 +00:00
doc.txt database/sql: fix outdated package name in doc.txt 2017-06-30 19:11:17 +00:00
example_cli_test.go database/sql: add examples for opening and testing a DB pool 2018-11-16 17:17:09 +00:00
example_service_test.go database/sql: add examples for opening and testing a DB pool 2018-11-16 17:17:09 +00:00
example_test.go database/sql: fix incorrect function name in example_test 2020-04-28 14:05:09 +00:00
fakedb_test.go database/sql: prevent Tx statement from committing after rollback 2020-04-20 17:45:50 +00:00
sql.go [release-branch.go1.15] database/sql: fix tx stmt deadlock when rollback 2021-03-30 21:41:42 +00:00
sql_test.go [release-branch.go1.15] database/sql: fix tx stmt deadlock when rollback 2021-03-30 21:41:42 +00:00