Skip to content

Commit

Permalink
backend: avoid deadlock
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benma committed Dec 5, 2023
1 parent 7b52130 commit 8136352
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,13 +910,14 @@ func (backend *Backend) SetWatchonly(watchonly bool) error {
nil,
)
}

accounts := accountsList(backend.Accounts())
// When enabling watchonly, we turn the currently loaded accounts into watch-only accounts.
t := true
return backend.AccountSetWatch(
func(account *config.Account) bool {
// Apply to each currently loaded account.
defer backend.accountsAndKeystoreLock.RLock()()
return backend.accounts.lookup(account.Code) != nil
return accounts.lookup(account.Code) != nil
},
&t,
)
Expand Down

0 comments on commit 8136352

Please sign in to comment.