Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions accounts/keystore/account_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func (ac *accountCache) maybeReload() {
ac.watcher.start()
ac.throttle.Reset(minReloadInterval)
ac.mu.Unlock()
ac.watcher.wg.Wait()
ac.scanAccounts()
}

Expand Down
7 changes: 7 additions & 0 deletions accounts/keystore/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package keystore

import (
"os"
"sync"
"time"

"github.com/ethereum/go-ethereum/log"
Expand All @@ -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{},
}
}

Expand All @@ -52,6 +55,7 @@ func (w *watcher) start() {
if w.starting || w.running {
return
}
w.wg.Add(1)
w.starting = true
go w.loop()
}
Expand All @@ -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
}

Expand All @@ -104,6 +110,7 @@ func (w *watcher) loop() {
<-debounce.C
}
defer debounce.Stop()
w.wg.Done()
for {
select {
case <-w.quit:
Expand Down