summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-23 02:52:58 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-23 02:52:58 -0400
commit8b6ab9931229947bba43eb8fe580637c11e8d591 (patch)
tree4a397ea2c2a871d01a232cac965aeb742641fc42
parentf316396ab1f6792e52ad4533397c07845d90eb07 (diff)
downloadgetwtxt-8b6ab9931229947bba43eb8fe580637c11e8d591.tar.gz
mutex RLock for remoteRegistries on recache/dbpush
-rw-r--r--cache.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/cache.go b/cache.go
index 6496775..691eb06 100644
--- a/cache.go
+++ b/cache.go
@@ -56,12 +56,14 @@ func refreshCache() {
 	// Re-scrape all the remote registries
 	// to see if they have any new users
 	// to add locally.
+	remoteRegistries.Mu.RLock()
 	for _, v := range remoteRegistries.List {
 		err := twtxtCache.ScrapeRemoteRegistry(v)
 		if err != nil {
 			log.Printf("Error while refreshing local copy of remote registry user data: %v\n", err)
 		}
 	}
+	remoteRegistries.Mu.RUnlock()
 	confObj.Mu.Lock()
 	confObj.LastCache = time.Now()
 	confObj.Mu.Unlock()
@@ -95,9 +97,11 @@ func pushDatabase() error {
 	twtxtCache.Mu.RUnlock()
 
 	// Save our list of remote registries to scrape.
+	remoteRegistries.Mu.RLock()
 	for k, v := range remoteRegistries.List {
 		dbBasket.Put([]byte("remote*"+string(k)), []byte(v))
 	}
+	remoteRegistries.Mu.RUnlock()
 
 	// Execute the batch job.
 	if err := db.Write(dbBasket, nil); err != nil {