aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/keystore/watch.go
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2017-10-09 18:40:50 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-10-09 18:40:50 +0800
commit88b1db728826efd499ea407579f41e8b683d6b53 (patch)
tree0e9d644ce23fefdbff83fd9d7075f99739fcb1e9 /accounts/keystore/watch.go
parent7a045af05b93c323f63c7af41423ded701ce3890 (diff)
downloaddexon-88b1db728826efd499ea407579f41e8b683d6b53.tar
dexon-88b1db728826efd499ea407579f41e8b683d6b53.tar.gz
dexon-88b1db728826efd499ea407579f41e8b683d6b53.tar.bz2
dexon-88b1db728826efd499ea407579f41e8b683d6b53.tar.lz
dexon-88b1db728826efd499ea407579f41e8b683d6b53.tar.xz
dexon-88b1db728826efd499ea407579f41e8b683d6b53.tar.zst
dexon-88b1db728826efd499ea407579f41e8b683d6b53.zip
accounts/keystore: scan key directory without locks held (#15171)
The accountCache contains a file cache, and remembers from scan to scan what files were present earlier. Thus, whenever there's a change, the scan phase only bothers processing new and removed files.
Diffstat (limited to 'accounts/keystore/watch.go')
-rw-r--r--accounts/keystore/watch.go25
1 files changed, 8 insertions, 17 deletions
diff --git a/accounts/keystore/watch.go b/accounts/keystore/watch.go
index f4d647791..602300b10 100644
--- a/accounts/keystore/watch.go
+++ b/accounts/keystore/watch.go
@@ -70,7 +70,6 @@ func (w *watcher) loop() {
return
}
defer notify.Stop(w.ev)
-
logger.Trace("Started watching keystore folder")
defer logger.Trace("Stopped watching keystore folder")
@@ -82,9 +81,9 @@ func (w *watcher) loop() {
// When an event occurs, the reload call is delayed a bit so that
// multiple events arriving quickly only cause a single reload.
var (
- debounce = time.NewTimer(0)
- debounceDuration = 500 * time.Millisecond
- inCycle, hadEvent bool
+ debounce = time.NewTimer(0)
+ debounceDuration = 500 * time.Millisecond
+ rescanTriggered = false
)
defer debounce.Stop()
for {
@@ -92,22 +91,14 @@ func (w *watcher) loop() {
case <-w.quit:
return
case <-w.ev:
- if !inCycle {
+ // Trigger the scan (with delay), if not already triggered
+ if !rescanTriggered {
debounce.Reset(debounceDuration)
- inCycle = true
- } else {
- hadEvent = true
+ rescanTriggered = true
}
case <-debounce.C:
- w.ac.mu.Lock()
- w.ac.reload()
- w.ac.mu.Unlock()
- if hadEvent {
- debounce.Reset(debounceDuration)
- inCycle, hadEvent = true, false
- } else {
- inCycle, hadEvent = false, false
- }
+ w.ac.scanAccounts()
+ rescanTriggered = false
}
}
}