Skip to content

Commit

Permalink
fix: do not panic on cleaning up failed iterators (#21666) (#23319)
Browse files Browse the repository at this point in the history
We have seen occasional panics in Iterators.Close()
when cleaning up after failed iterator creation.
This commit checks for nil on any iterator to be
closed, and now returns any errors generated by
that Close().

Closes #19579
Closes #19476

(cherry picked from commit acc4105)

closes #23271
  • Loading branch information
davidby-influx authored Apr 29, 2022
1 parent 71a02c2 commit 9c33764
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions influxql/query/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,22 @@ func (a Iterators) Stats() IteratorStats {
}

// Close closes all iterators.
func (a Iterators) Close() error {
// We are seeing an occasional panic in this function
// which looks like a nil reference from one
// itr.Close() call, thus we check for nil elements
// in the slice a. This is often called as error
// clean-up, so the state of the iterators may be
// unhappy.
func (a Iterators) Close() (err error) {
err = nil
for _, itr := range a {
itr.Close()
if itr != nil {
if e := itr.Close(); e != nil && err == nil {
err = e
}
}
}
return nil
return err
}

// filterNonNil returns a slice of iterators that removes all nil iterators.
Expand Down

0 comments on commit 9c33764

Please sign in to comment.