From 2e6d978e3573e22dc0fe91b9e7a8b2e0043835ab Mon Sep 17 00:00:00 2001 From: Herbert Date: Tue, 17 Jun 2025 14:44:51 +0200 Subject: [PATCH] accounts: fix data race when closing manager (#31982) 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. --- accounts/manager.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/accounts/manager.go b/accounts/manager.go index ac21ecd985..a2218e54dd 100644 --- a/accounts/manager.go +++ b/accounts/manager.go @@ -93,9 +93,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 @@ -149,6 +146,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