Skip to content

Commit

Permalink
fix: do not panic on cleaning up failed iterators (influxdata#21666) (i…
Browse files Browse the repository at this point in the history
…nfluxdata#21697)

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 influxdata#19579
Closes influxdata#19476

(cherry picked from commit acc4105)

Closes influxdata#21667
  • Loading branch information
davidby-influx authored Jun 15, 2021
1 parent 9355183 commit ae851d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[unreleased]
v1.9.3 [unreleased]

### Bugfixes

- [#21609](https://github.com/influxdata/influxdb/pull/21609): fix: avoid rewriting fields.idx unnecessarily
- [#21695](https://github.com/influxdata/influxdb/pull/21695): fix: Do not close connection twice in DigestWithOptions
- [#21697](https://github.com/influxdata/influxdb/pull/21697): fix: do not panic on cleaning up failed iterators

v1.9.2 [unreleased]

Expand Down
17 changes: 14 additions & 3 deletions 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 ae851d9

Please sign in to comment.