Skip to content

Commit

Permalink
accounts: properly close managed wallets when closing manager (#28710)
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman authored Dec 20, 2023
1 parent 7124057 commit d3452a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions accounts/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func NewManager(config *Config, backends ...Backend) *Manager {

// Close terminates the account manager's internal notification processes.
func (am *Manager) Close() error {
for _, w := range am.wallets {
w.Close()
}
errc := make(chan error)
am.quit <- errc
return <-errc
Expand Down
4 changes: 4 additions & 0 deletions accounts/usbwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ func (w *wallet) Derive(path accounts.DerivationPath, pin bool) (accounts.Accoun
w.stateLock.Lock()
defer w.stateLock.Unlock()

if w.device == nil {
return accounts.Account{}, accounts.ErrWalletClosed
}

if _, ok := w.paths[address]; !ok {
w.accounts = append(w.accounts, account)
w.paths[address] = make(accounts.DerivationPath, len(path))
Expand Down
1 change: 1 addition & 0 deletions cmd/clef/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ func signer(c *cli.Context) error {
log.Info("Starting signer", "chainid", chainId, "keystore", ksLoc,
"light-kdf", lightKdf, "advanced", advanced)
am := core.StartClefAccountManager(ksLoc, nousb, lightKdf, scpath)
defer am.Close()
apiImpl := core.NewSignerAPI(am, chainId, nousb, ui, db, advanced, pwStorage)

// Establish the bidirectional communication, by creating a new UI backend and registering
Expand Down

0 comments on commit d3452a2

Please sign in to comment.