From d7846ec7e013d40f8d67424799d7212837d8d653 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Thu, 13 Aug 2020 10:41:28 +0800 Subject: [PATCH] grab lookup len under read lock --- bucket.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bucket.go b/bucket.go index 3c09015..e9100bb 100644 --- a/bucket.go +++ b/bucket.go @@ -56,7 +56,12 @@ func (b *bucket) delete(key string) *Item { // write lock) func (b *bucket) deleteFunc(matches func(key string, item interface{}) bool, deletables chan *Item) int { lookup := b.lookup - items := make([]*Item, 0, len(lookup)/10) + + b.RLock() + l := len(lookup) + b.RUnlock() + + items := make([]*Item, 0, l/10) b.RLock() for key, item := range lookup {