From 5f2002bbcc1ad21818d9b08badea84acac6d0481 Mon Sep 17 00:00:00 2001 From: Boqin Qin Date: Wed, 12 Feb 2020 22:20:50 +0800 Subject: [PATCH] accounts: add walletsNoLock to avoid double read lock (#20655) --- accounts/manager.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/accounts/manager.go b/accounts/manager.go index 731d12ea3..acf41ed8e 100644 --- a/accounts/manager.go +++ b/accounts/manager.go @@ -141,6 +141,11 @@ func (am *Manager) Wallets() []Wallet { am.lock.RLock() defer am.lock.RUnlock() + return am.walletsNoLock() +} + +// walletsNoLock returns all registered wallets. Callers must hold am.lock. +func (am *Manager) walletsNoLock() []Wallet { cpy := make([]Wallet, len(am.wallets)) copy(cpy, am.wallets) return cpy @@ -155,7 +160,7 @@ func (am *Manager) Wallet(url string) (Wallet, error) { if err != nil { return nil, err } - for _, wallet := range am.Wallets() { + for _, wallet := range am.walletsNoLock() { if wallet.URL() == parsed { return wallet, nil }