Skip to content

Commit 8136352

Browse files
committed
backend: avoid deadlock
backend.AccountSetWatch holds the accounts config lock while it is modifying the config, and while it holds the config lock it tries to acquire the accountsAndKeystoreLock in the filter function. This can deadlock if the accountsAndKeystoreLock is held already.
1 parent 7b52130 commit 8136352

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

backend/backend.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,13 +910,14 @@ func (backend *Backend) SetWatchonly(watchonly bool) error {
910910
nil,
911911
)
912912
}
913+
914+
accounts := accountsList(backend.Accounts())
913915
// When enabling watchonly, we turn the currently loaded accounts into watch-only accounts.
914916
t := true
915917
return backend.AccountSetWatch(
916918
func(account *config.Account) bool {
917919
// Apply to each currently loaded account.
918-
defer backend.accountsAndKeystoreLock.RLock()()
919-
return backend.accounts.lookup(account.Code) != nil
920+
return accounts.lookup(account.Code) != nil
920921
},
921922
&t,
922923
)

0 commit comments

Comments
 (0)