btcsuite / btcwallet

A secure bitcoin wallet daemon written in Go (golang)
ISC License
1.15k stars 590 forks source link

waddrmgr: fix deadlock #967

Closed aakselrod closed 1 week ago

aakselrod commented 1 week ago

This PR fixes a deadlock caused by methods of ScopedManager read-locking the root manager for WatchOnly() and Locked() calls while the ScopedManager itself is locked. This is the reverse order from the normal way of taking locks, but has been hidden by the fact that DB transactions have never happened in parallel until the upcoming postgres changes in LND.

See discussion here for more details.

The first commit updates a test to cause this failure. The following commits, pushed after CI completes/tests fail, contain the fix.