accounts/keystore: use runtime.AddCleanup #32610 (#1580)

Co-authored-by: cui <cuiweixie@gmail.com>
This commit is contained in:
wit liu 2025-10-08 12:29:03 +08:00 committed by GitHub
parent 9b0a653698
commit 09b6622165
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -99,9 +99,10 @@ func (ks *KeyStore) init(keydir string) {
// TODO: In order for this finalizer to work, there must be no references
// to ks. addressCache doesn't keep a reference but unlocked keys do,
// so the finalizer will not trigger until all timed unlocks have expired.
runtime.SetFinalizer(ks, func(m *KeyStore) {
m.cache.close()
})
runtime.AddCleanup(ks, func(c *accountCache) {
c.close()
}, ks.cache)
// Create the initial list of wallets from the cache
accs := ks.cache.accounts()
ks.wallets = make([]accounts.Wallet, len(accs))