Prevent a panic when a query simultaneously finishes and is killed at the same time

There is a strange race condition where a query can be killed and finish
at approximately the same time. If this happens, the query gets
retrieved by the killing task, the query gets closed by the normal
processing thread, and then the killing task attempts to kill the query
afterwards. Since the close doesn't mark the query as already killed
(since it's not killed, just merely unused), the killing thread attempts
to close the channel again.

Mark the query as killed whenever it is closed to prevent a double close
from happening. This should never cause the status to be erroneously
reported since the query status is removed from the query table within
the same lock scope.
pull/9220/head
Jonathan A. Sternberg 2017-12-11 16:44:49 -06:00
parent 80f1120c3e
commit ecba19eb27
2 changed files with 3 additions and 0 deletions

View File

@ -28,6 +28,7 @@
- [#9230](https://github.com/influxdata/influxdb/pull/9230): Remove extraneous newlines from the log.
- [#9226](https://github.com/influxdata/influxdb/issues/9226): Allow lone boolean literals in a condition expression.
- [#9235](https://github.com/influxdata/influxdb/pull/9235): Improve performance when writes exceed `max-values-per-tag` or `max-series`.
- [#9216](https://github.com/influxdata/influxdb/issues/9216): Prevent a panic when a query simultaneously finishes and is killed at the same time.
## v1.4.3 [unreleased]

View File

@ -508,6 +508,8 @@ func (q *QueryTask) monitor(fn QueryMonitorFunc) {
func (q *QueryTask) close() {
q.mu.Lock()
if q.status != KilledTask {
// Set the status to killed to prevent closing the channel twice.
q.status = KilledTask
close(q.closing)
}
q.mu.Unlock()