From 09b66221653db8ba5f8ae4f0b3ca32542d68e15e Mon Sep 17 00:00:00 2001 From: wit liu <765765346@qq.com> Date: Wed, 8 Oct 2025 12:29:03 +0800 Subject: [PATCH] accounts/keystore: use runtime.AddCleanup #32610 (#1580) Co-authored-by: cui --- accounts/keystore/keystore.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/accounts/keystore/keystore.go b/accounts/keystore/keystore.go index 1e18e23ac4..e03d2582f2 100644 --- a/accounts/keystore/keystore.go +++ b/accounts/keystore/keystore.go @@ -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))