btcsuite / btcwallet

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

Deadlock potential #942

Open JssDWt opened 3 months ago

JssDWt commented 3 months ago

The importScriptAddress function of ScopedKeyManager takes a Lock on ScopedKeyManager, then a Lock on Manager.

The Address function of Manager takes a RLock on Manager, then a RLock/Lock on ScopedKeyManager.

Combining the two can lead to a deadlock.

JssDWt commented 3 months ago

There's other occasions too where the locks of manager and scoped manager are reversed. A decision must be made:

Probably manager first, then scoped manager makes most sense. ImportPublicKey and importScriptAddress have this issue

JssDWt commented 1 month ago

We've been using this, apparently successfully, over the last few months: https://github.com/breez/btcwallet/commit/04ba1085f2dcdbb028163a3a489efa17226b7f07

Let me know if I should PR that.

guggero commented 1 month ago

Looks like a worthy PR, sure. Thanks for investigating in the first place!

JssDWt commented 1 month ago

Looks like a worthy PR, sure. Thanks for investigating in the first place!

https://github.com/btcsuite/btcwallet/issues/942