Skip to content

Commit

Permalink
fix: do not panic on cleaning up failed iterators (influxdata#21666)
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 influxdata#19579
Closes influxdata#19476
  • Loading branch information
davidby-influx authored and chengshiwen committed Aug 27, 2024
1 parent 9fbd792 commit e407f99
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ v1.8.11 [unreleased]
- [#18429](https://github.com/influxdata/influxdb/pull/18429): Add option to authenticate prometheus remote read
- [#21592](https://github.com/influxdata/influxdb/pull/21592): fix: avoid rewriting fields.idx unnecessarily
- [#21659](https://github.com/influxdata/influxdb/pull/21659): fix: do not close connection twice in DigestWithOptions
- [#21666](https://github.com/influxdata/influxdb/pull/21666): fix: do not panic on cleaning up failed iterators

v1.8.10 [2021-10-11]
-------------------
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 e407f99

Please sign in to comment.