Skip to content

Commit

Permalink
fix: Do not panic on cleaning up failed iterators
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
  • Loading branch information
davidby-influx committed Jun 11, 2021
1 parent bce6553 commit 370a912
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions query/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,23 @@ func (a Iterators) Stats() IteratorStats {
}

// Close closes all iterators.
func (a Iterators) Close() error {
for _, itr := range a {
itr.Close()
// 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
if a != nil {
for _, itr := range a {
if itr != nil {
if e := itr.Close(); e != nil && err == nil {
err = e
}
}
}
return err
}
return nil
}
Expand Down

0 comments on commit 370a912

Please sign in to comment.