]> Cypherpunks repositories - gostls13.git/commit
database/sql: fix tx stmt deadlock when rollback
authorTzu-Chiao Yeh <su3g4284zo6y7@gmail.com>
Mon, 24 Aug 2020 14:04:17 +0000 (22:04 +0800)
committerEmmanuel Odeke <emmanuel@orijtech.com>
Wed, 28 Oct 2020 16:55:17 +0000 (16:55 +0000)
commitd4c1ad882973e407ff85b977f4ce5b9435451190
treef3681fb1fdb68a84f0ca3e3567f69055a61da0bb
parent421d4e72de802ed65cb38317660654771cfb13e9
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.

Fixes #40985

Change-Id: If53909822b87bce11861a6e3035ecb9476d2cd17
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>
src/database/sql/sql.go
src/database/sql/sql_test.go