influxdata / influxdb

Scalable datastore for metrics, events, and real-time analytics
https://influxdata.com
Apache License 2.0
28.92k stars 3.55k forks source link

Panic when executing query that uses regular expressions to match measurements #22857

Open stuartcarnie opened 2 years ago

stuartcarnie commented 2 years ago

InfluxDB: OSS 1.8.9

A community member has reported an error when executing queries that contain regular expressions and has provided the following call stack:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x963de0]

goroutine 48889834 [running]:
github.com/influxdata/influxdb/query.Iterators.Close(0xc721afc480, 0xb, 0x24, 0xc48fb98a50, 0x25b6ea0)
    /go/src/github.com/influxdata/influxdb/query/iterator.go:48 +0x50
github.com/influxdata/influxdb/coordinator.(*LocalShardMapping).CreateIterator(0xc502847880, 0x25a5300, 0xc491cb2960, 0xc48fb98a50, 0x259a240, 0xc491cb2a80, 0x0, 0x0, 0x0, 0x0, ...)
    /go/src/github.com/influxdata/influxdb/coordinator/shard_mapper.go:202 +0x33a
github.com/influxdata/influxdb/query.(*exprIteratorBuilder).callIterator.func1(0xc4b81458f0, 0x25a5300, 0xc491cb2960, 0xc4b8143be0, 0xc4b8143b98, 0xc491cb2a80, 0x430042ff42fb42f8, 0x4308430743044303)
    /go/src/github.com/influxdata/influxdb/query/select.go:583 +0x15e
github.com/influxdata/influxdb/query.(*exprIteratorBuilder).callIterator(0xc48623f8f0, 0x25a5300, 0xc491cb2960, 0xc491cb2a80, 0x259a240, 0xc491cb2a80, 0x0, 0x0, 0x0, 0x0, ...)
    /go/src/github.com/influxdata/influxdb/query/select.go:608 +0xdf
github.com/influxdata/influxdb/query.(*exprIteratorBuilder).buildCallIterator.func1(0xc491cb2a80, 0x25a5300, 0xc491cb2960, 0xc48623f8f0, 0xc48623edd0, 0x259a340, 0xc491e26050, 0x8, 0x7fdc3f3e8b28)
    /go/src/github.com/influxdata/influxdb/query/select.go:515 +0xf5
github.com/influxdata/influxdb/query.(*exprIteratorBuilder).buildCallIterator(0xc4b81458f0, 0x25a5300, 0xc491cb2960, 0xc491cb2a80, 0x4b, 0xc00ca44e60, 0x52, 0xa0)
    /go/src/github.com/influxdata/influxdb/query/select.go:559 +0xd3e
github.com/influxdata/influxdb/query.buildExprIterator(0x25a5300, 0xc491cb2960, 0x259a240, 0xc491cb2a80, 0x7f9c289d8c48, 0xc502847880, 0xc48fbe7910, 0x1, 0x1, 0x259a240, ...)
    /go/src/github.com/influxdata/influxdb/query/select.go:156 +0x1f4
github.com/influxdata/influxdb/query.buildFieldIterator(0x25a5300, 0xc491cb2960, 0x259a240, 0xc491cb2a80, 0x7f9c289d8c48, 0xc502847880, 0xc48fbe7910, 0x1, 0x1, 0x0, ...)
    /go/src/github.com/influxdata/influxdb/query/select.go:870 +0x489
github.com/influxdata/influxdb/query.buildCursor.func1(0xc422738f68, 0x7f9c9ef8a201)
    /go/src/github.com/influxdata/influxdb/query/select.go:744 +0x127
github.com/influxdata/influxdb/vendor/golang.org/x/sync/errgroup.(*Group).Go.func1(0xc491cb2ab0, 0xc4728c3a40)
    /go/src/github.com/influxdata/influxdb/vendor/golang.org/x/sync/errgroup/errgroup.go:57 +0x64
created by github.com/influxdata/influxdb/vendor/golang.org/x/sync/errgroup.(*Group).Go
    /go/src/github.com/influxdata/influxdb/vendor/golang.org/x/sync/errgroup/errgroup.go:54 +0x66

The nil pointer dereference occurs here:

https://github.com/influxdata/influxdb/blob/d9b56321d5796d7791138ed6a8f0a6ae6007a551/query/iterator.go#L48

as a result of an error being raised here:

https://github.com/influxdata/influxdb/blob/d9b56321d5796d7791138ed6a8f0a6ae6007a551/coordinator/shard_mapper.go#L188-L204

suggesting that prior to the error occurring, a nil iterator was added to the inputs slice:

https://github.com/influxdata/influxdb/blob/d9b56321d5796d7791138ed6a8f0a6ae6007a551/coordinator/shard_mapper.go#L194

It appears that calling filterNonNil is a common pattern for eliminating nil iterators, prior to performing subsequent operations:

https://github.com/influxdata/influxdb/blob/d9b56321d5796d7791138ed6a8f0a6ae6007a551/query/iterator.go#L53-L54

bargru commented 2 years ago

I have the same error with InfluxDB OSS 1.8.10 running on Ubuntu 20.04.

kward-influx commented 2 years ago

@stuartcarnie another report of this error has surfaced in 1.8.10:

panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x963de0] goroutine 3552892630 [running]: [github.com/influxdata/influxdb/query.Iterators.Close](https://github.com/influxdata/influxdb/query.Iterators.Close)(0xc255237e90, 0x2, 0x3, 0xc25502f5e0, 0x25b6fe0) /go/src/[github.com/influxdata/influxdb/query/iterator.go:48](https://github.com/influxdata/influxdb/query/iterator.go:48) +0x50

Marc-Assmann commented 2 years ago

See the same with InfluxDB OSS 1.8.10 in docker:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x963de0]
goroutine 1211408 [running]:
[github.com/influxdata/influxdb/query.Iterators.Close(0xc177f9c000](http://github.com/influxdata/influxdb/query.Iterators.Close(0xc177f9c000), 0x7a, 0x171, 0xc177cf6190, 0x25b6fe0)
        /go/src/github.com/influxdata/influxdb/query/iterator.go:48 +0x50
Marc-Assmann commented 2 years ago

This seems to be a duplicate of #21649