From acc4105b8c48657287ddeaed56c28fd2840dd862 Mon Sep 17 00:00:00 2001 From: davidby-influx <72418212+davidby-influx@users.noreply.github.com> Date: Fri, 11 Jun 2021 11:28:59 -0700 Subject: [PATCH] fix: do not panic on cleaning up failed iterators (#21666) 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 https://github.com/influxdata/influxdb/issues/19579 Closes https://github.com/influxdata/influxdb/issues/19476 --- CHANGELOG.md | 4 ++++ query/iterator.go | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 262616e2504..4e14c7af4b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ v1.9.3 [unreleased] + +#### Bugfixes + - [#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.9.2 [unreleased] - [#21631](https://github.com/influxdata/influxdb/pull/21631): fix: group by returns multiple results per group in some circumstances diff --git a/query/iterator.go b/query/iterator.go index 81ff89f93af..95064390451 100644 --- a/query/iterator.go +++ b/query/iterator.go @@ -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.