fix: handle a potential nil iterator leading to a panic (#23520)

* fix: handle a potential nil iterator leading to a panic

* chore: cleanup
pull/23844/head
Jeffrey Smith II 2022-10-31 08:54:57 -04:00 committed by GitHub
parent 1033334482
commit 9582826b3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -547,10 +547,18 @@ func (s *Store) measurementFields(ctx context.Context, mqAttrs *metaqueryAttribu
if err != nil {
return nil, err
}
defer func() { _ = iter.Close() }()
defer func() {
if iter != nil {
_ = iter.Close()
}
}()
var fieldNames []string
fitr := iter.(query.FloatIterator)
fitr, ok := iter.(query.FloatIterator)
if !ok {
return cursors.NewStringSliceIterator(fieldNames), nil
}
for p, _ := fitr.Next(); p != nil; p, _ = fitr.Next() {
if len(p.Aux) >= 1 {
fieldNames = append(fieldNames, p.Aux[0].(string))