remove waitgroup and apply a straightforward fix

This commit is contained in:
steven 2024-05-29 13:54:08 +08:00
parent 6d6183762c
commit d255b54cf6
3 changed files with 13 additions and 17 deletions

View file

@ -220,7 +220,6 @@ func (ac *accountCache) maybeReload() {
ac.watcher.start() ac.watcher.start()
ac.throttle.Reset(minReloadInterval) ac.throttle.Reset(minReloadInterval)
ac.mu.Unlock() ac.mu.Unlock()
ac.watcher.startupWG.Wait()
ac.scanAccounts() ac.scanAccounts()
} }

View file

@ -326,6 +326,11 @@ func TestUpdatedKeyfileContents(t *testing.T) {
// Create a temporary keystore to test with // Create a temporary keystore to test with
dir := filepath.Join(os.TempDir(), fmt.Sprintf("eth-keystore-updatedkeyfilecontents-test-%d-%d", os.Getpid(), rand.Int())) dir := filepath.Join(os.TempDir(), fmt.Sprintf("eth-keystore-updatedkeyfilecontents-test-%d-%d", os.Getpid(), rand.Int()))
// Create the directory
os.MkdirAll(dir, 0700)
defer os.RemoveAll(dir)
ks := NewKeyStore(dir, LightScryptN, LightScryptP) ks := NewKeyStore(dir, LightScryptN, LightScryptP)
list := ks.Accounts() list := ks.Accounts()
@ -335,9 +340,7 @@ func TestUpdatedKeyfileContents(t *testing.T) {
if !waitWatcherStart(ks) { if !waitWatcherStart(ks) {
t.Fatal("keystore watcher didn't start in time") t.Fatal("keystore watcher didn't start in time")
} }
// Create the directory and copy a key file into it. // Copy a key file into it
os.MkdirAll(dir, 0700)
defer os.RemoveAll(dir)
file := filepath.Join(dir, "aaa") file := filepath.Join(dir, "aaa")
// Place one of our testfiles in there // Place one of our testfiles in there

View file

@ -21,7 +21,6 @@ package keystore
import ( import (
"os" "os"
"sync"
"time" "time"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
@ -34,14 +33,12 @@ type watcher struct {
runEnded bool // set to true when runloop ends runEnded bool // set to true when runloop ends
starting bool // set to true prior to runloop starting starting bool // set to true prior to runloop starting
quit chan struct{} quit chan struct{}
startupWG sync.WaitGroup // wait for watcher loop to start
} }
func newWatcher(ac *accountCache) *watcher { func newWatcher(ac *accountCache) *watcher {
return &watcher{ return &watcher{
ac: ac, ac: ac,
quit: make(chan struct{}), quit: make(chan struct{}),
startupWG: sync.WaitGroup{},
} }
} }
@ -55,7 +52,6 @@ func (w *watcher) start() {
if w.starting || w.running { if w.starting || w.running {
return return
} }
w.startupWG.Add(1)
w.starting = true w.starting = true
go w.loop() go w.loop()
} }
@ -85,7 +81,6 @@ func (w *watcher) loop() {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
logger.Warn("Failed to watch keystore folder", "err", err) logger.Warn("Failed to watch keystore folder", "err", err)
} }
w.startupWG.Done()
return return
} }
@ -109,7 +104,6 @@ func (w *watcher) loop() {
<-debounce.C <-debounce.C
} }
defer debounce.Stop() defer debounce.Stop()
w.startupWG.Done()
for { for {
select { select {
case <-w.quit: case <-w.quit: