From 27dfed7f275632831f005421024b94c5092e1b42 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 19 Feb 2018 18:31:29 -0800 Subject: [PATCH] waddrmgr: fix deadlock bug by using read mutex when necessary In this commit, we fix a deadlock bug that was introduced recently. This can happen when ForEachActiveAccountAddress or ForEachActiveAddress is called, as these internally need to grab the mutex of the manager (within the scoped manager) in order to check if the manager is locked or not. --- waddrmgr/manager.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/waddrmgr/manager.go b/waddrmgr/manager.go index a66f62a..6c6e6e3 100644 --- a/waddrmgr/manager.go +++ b/waddrmgr/manager.go @@ -686,8 +686,8 @@ func (m *Manager) ForEachActiveAccountAddress(ns walletdb.ReadBucket, // ForEachActiveAddress calls the given function with each active address // stored in the manager, breaking early on error. func (m *Manager) ForEachActiveAddress(ns walletdb.ReadBucket, fn func(addr btcutil.Address) error) error { - m.mtx.Lock() - defer m.mtx.Unlock() + m.mtx.RLock() + defer m.mtx.RUnlock() for _, scopedMgr := range m.scopedManagers { err := scopedMgr.ForEachActiveAddress(ns, fn) @@ -704,8 +704,8 @@ func (m *Manager) ForEachActiveAddress(ns walletdb.ReadBucket, fn func(addr btcu func (m *Manager) ForEachAccountAddress(ns walletdb.ReadBucket, account uint32, fn func(maddr ManagedAddress) error) error { - m.mtx.Lock() - defer m.mtx.Unlock() + m.mtx.RLock() + defer m.mtx.RUnlock() for _, scopedMgr := range m.scopedManagers { err := scopedMgr.ForEachAccountAddress(ns, account, fn)