]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.15] database/sql: fix tx stmt deadlock when rollback
authorEmmanuel T Odeke <emmanuel@orijtech.com>
Tue, 19 Jan 2021 00:18:11 +0000 (16:18 -0800)
committerDmitri Shuralyov <dmitshur@golang.org>
Tue, 30 Mar 2021 21:41:42 +0000 (21:41 +0000)
commitc77418f4cac41c42566ca90921a1f928995cfba2
treeb91ee6f7e76ec9217db99abe94cf73e4a0564d76
parent6df5d3a581380a85183c591d1fd9063a5e8e4b23
[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 d4c1ad882973e407ff85b977f4ce5b9435451190)
Reviewed-on: https://go-review.googlesource.com/c/go/+/284513
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
src/database/sql/sql.go
src/database/sql/sql_test.go