From cdfc8c771301c8c1f32e50e773d620a6b8767078 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Sat, 14 Mar 2026 19:54:47 -0700 Subject: database/sql: avoid deadlock from reentrant RLock RWMutex.RLock blocks until any pending Lock operations are satisfied. This prohibits recursive read-locking. Replace various RWMutexes used to synchronize between reads and closes with a variant where the reader side takes priority. Reads can starve out Close, but will not deadlock. Fixes #78304 Change-Id: Id36529bf86bed5dbf22f2af94283aeac6a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/758064 Auto-Submit: Damien Neil Reviewed-by: Neal Patel LUCI-TryBot-Result: Go LUCI --- src/database/sql/sql_test.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/database/sql/sql_test.go') diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go index 5f093a2d6d..40da17472d 100644 --- a/src/database/sql/sql_test.go +++ b/src/database/sql/sql_test.go @@ -4483,6 +4483,8 @@ func testContextCancelDuringRawBytesScan(t *testing.T, mode string) { for _, b := range s { // some operation reading from the raw memory sink += b } + // r.Columns must not deadlock acquiring closemu.RLock. + _, _ = r.Columns() } if r.closemuScanHold { t.Errorf("closemu held; should not be") -- cgit v1.3