Tech Musings
Tech Musings
Mar 27, 2026 · Backend Development

Why Go’s database/sql Deadlock Needed a New closingMutex and How It Works

Go’s database/sql package can deadlock when a Scan holds a read lock, a cancelled context triggers Close, and Columns attempts another read lock, but the new closingMutex introduced in Go’s source replaces the generic sync.RWMutex to allow reads during pending writes, preventing the deadlock.

DeadlockGoTesting
0 likes · 16 min read
Why Go’s database/sql Deadlock Needed a New closingMutex and How It Works