From 9929bcc40d57e580af82a105ba530a7d9640e27c Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 14 Aug 2017 15:17:51 +0200 Subject: [PATCH] account/keystore : make fs watcher use not block account ops during fs scan --- accounts/keystore/account_cache.go | 6 ++++++ accounts/keystore/watch.go | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/accounts/keystore/account_cache.go b/accounts/keystore/account_cache.go index dc6ac6ccb3..77c19ddd9f 100644 --- a/accounts/keystore/account_cache.go +++ b/accounts/keystore/account_cache.go @@ -209,6 +209,12 @@ func (ac *accountCache) close() { // Callers must hold ac.mu. func (ac *accountCache) reload() { accounts, err := ac.scan() + ac.handleScanResult(accounts, err) +} + +// handleScanResult uses the result of a fs scan to update the account lists +// This can be used to perform un-mutexed fs scans +func (ac *accountCache) handleScanResult(accounts []accounts.Account, err error) { if err != nil { log.Debug("Failed to reload keystore contents", "err", err) } diff --git a/accounts/keystore/watch.go b/accounts/keystore/watch.go index f4d6477912..363587223d 100644 --- a/accounts/keystore/watch.go +++ b/accounts/keystore/watch.go @@ -99,8 +99,9 @@ func (w *watcher) loop() { hadEvent = true } case <-debounce.C: + accounts, err := w.ac.scan() w.ac.mu.Lock() - w.ac.reload() + w.ac.handleScanResult(accounts, err) w.ac.mu.Unlock() if hadEvent { debounce.Reset(debounceDuration)