From b4e83b1f8cc96567aff6be878f50dd03997f3bb9 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Wed, 20 Oct 2021 18:06:05 +0200 Subject: [PATCH] waddrmgr: fix concurrent map access Fixes lightningnetwork/lnd#5864. The loadAccountInfo does load an account as its name suggests. But after loading it, the account is also added to a map to cache it. That map write should be seen as a writing operation and therefore the _write_ lock must be held, not just the read lock. --- waddrmgr/scoped_manager.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/waddrmgr/scoped_manager.go b/waddrmgr/scoped_manager.go index 6d02c31..db188d9 100644 --- a/waddrmgr/scoped_manager.go +++ b/waddrmgr/scoped_manager.go @@ -518,8 +518,8 @@ func (s *ScopedKeyManager) loadAccountInfo(ns walletdb.ReadBucket, func (s *ScopedKeyManager) AccountProperties(ns walletdb.ReadBucket, account uint32) (*AccountProperties, error) { - defer s.mtx.RUnlock() - s.mtx.RLock() + s.mtx.Lock() + defer s.mtx.Unlock() props := &AccountProperties{ AccountNumber: account,