From 6a6bdab463ba5306251e82f1fa30425007f3d254 Mon Sep 17 00:00:00 2001 From: steven Date: Wed, 29 May 2024 02:09:16 +0800 Subject: [PATCH] accounts: fix TestUpdateKeyfileContents --- accounts/keystore/account_cache.go | 1 + accounts/keystore/watch.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/accounts/keystore/account_cache.go b/accounts/keystore/account_cache.go index f7cf688e62..f20f0f8af5 100644 --- a/accounts/keystore/account_cache.go +++ b/accounts/keystore/account_cache.go @@ -220,6 +220,7 @@ func (ac *accountCache) maybeReload() { ac.watcher.start() ac.throttle.Reset(minReloadInterval) ac.mu.Unlock() + ac.watcher.wg.Wait() ac.scanAccounts() } diff --git a/accounts/keystore/watch.go b/accounts/keystore/watch.go index 1bef321cd1..b4994082cb 100644 --- a/accounts/keystore/watch.go +++ b/accounts/keystore/watch.go @@ -21,6 +21,7 @@ package keystore import ( "os" + "sync" "time" "github.com/ethereum/go-ethereum/log" @@ -33,12 +34,14 @@ type watcher struct { runEnded bool // set to true when runloop ends starting bool // set to true prior to runloop starting quit chan struct{} + wg sync.WaitGroup // wait for watcher loop to start } func newWatcher(ac *accountCache) *watcher { return &watcher{ ac: ac, quit: make(chan struct{}), + wg: sync.WaitGroup{}, } } @@ -52,6 +55,7 @@ func (w *watcher) start() { if w.starting || w.running { return } + w.wg.Add(1) w.starting = true go w.loop() } @@ -77,10 +81,12 @@ func (w *watcher) loop() { return } defer watcher.Close() + if err := watcher.Add(w.ac.keydir); err != nil { if !os.IsNotExist(err) { logger.Warn("Failed to watch keystore folder", "err", err) } + w.wg.Done() return } @@ -104,6 +110,7 @@ func (w *watcher) loop() { <-debounce.C } defer debounce.Stop() + w.wg.Done() for { select { case <-w.quit: