From aec5f28dab4209c74a3e55373cd213605b529399 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Wed, 3 Sep 2025 15:49:24 +0800 Subject: [PATCH] accounts: fix data race when closing manager #31982 (#1423) Fixes a data race on the `wallets` slice when closing account Manager. At the moment, there is a data race between a go-routine calling the Manager's `Close` function and the background go-routine handling most operations on the `Manager`. The `Manager`'s `wallets` field is accessed without proper synchronization. By moving the closing of wallets from the `Close()` function into the background thread, this issue can be resolved. Co-authored-by: Herbert --- accounts/manager.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/accounts/manager.go b/accounts/manager.go index f525052c82..aafb93af96 100644 --- a/accounts/manager.go +++ b/accounts/manager.go @@ -98,9 +98,6 @@ 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 @@ -159,6 +156,10 @@ func (am *Manager) update() { am.lock.Unlock() close(event.processed) case errc := <-am.quit: + // Close all owned wallets + for _, w := range am.wallets { + w.Close() + } // Manager terminating, return errc <- nil // Signals event emitters the loop is not receiving values