From e5ffed35a4da4cf49751963ddc47d6eee8614a65 Mon Sep 17 00:00:00 2001 From: Seebs Date: Fri, 11 Oct 2019 14:44:25 -0500 Subject: [PATCH] use labeled targets for break statements break in a select in a for terminates the current case of the select, but does not terminate the for loop. The worker queue implementations for opening indexes/fields/views all suffered from the same issue here. Also fix a `<= 0` on a uint value. All hail staticcheck. --- field.go | 3 ++- index.go | 3 ++- translate.go | 2 +- view.go | 6 ++++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/field.go b/field.go index 917276ef3..38b364b67 100644 --- a/field.go +++ b/field.go @@ -468,10 +468,11 @@ func (f *Field) openViews() error { eg, ctx := errgroup.WithContext(context.Background()) var mu sync.Mutex +fileLoop: for _, loopFi := range fis { select { case <-ctx.Done(): - break + break fileLoop default: fi := loopFi if !fi.IsDir() { diff --git a/index.go b/index.go index 9f7e790ff..5c73809c1 100644 --- a/index.go +++ b/index.go @@ -174,10 +174,11 @@ func (i *Index) openFields() error { eg, ctx := errgroup.WithContext(context.Background()) var mu sync.Mutex +fileLoop: for _, loopFi := range fis { select { case <-ctx.Done(): - break + break fileLoop default: fi := loopFi if !fi.IsDir() { diff --git a/translate.go b/translate.go index 3fccb0b76..3a2a6891f 100644 --- a/translate.go +++ b/translate.go @@ -301,7 +301,7 @@ func (s *InMemTranslateStore) TranslateIDs(ids []uint64) ([]string, error) { } func (s *InMemTranslateStore) translateID(id uint64) string { - if id <= 0 || id > uint64(len(s.keys)) { + if id == 0 || id > uint64(len(s.keys)) { return "" } return s.keys[id-1] diff --git a/view.go b/view.go index 72700c9b6..cd976240a 100644 --- a/view.go +++ b/view.go @@ -134,10 +134,11 @@ func (v *view) openFragments() error { eg, ctx := errgroup.WithContext(context.Background()) var mu sync.Mutex +fileLoop: for _, loopFi := range fis { select { case <-ctx.Done(): - break + break fileLoop default: fi := loopFi @@ -181,10 +182,11 @@ func (v *view) close() error { // Close all fragments. eg, ctx := errgroup.WithContext(context.Background()) +fragLoop: for _, loopFrag := range v.fragments { select { case <-ctx.Done(): - break + break fragLoop default: frag := loopFrag workQueue <- struct{}{}