influxdata / influxdata/influxdb

Runtime error when combining derivative() with if in flux query

Open
#22,939 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

This query leads to _runtime error: invalid memory address or nil pointer dereference_:
```
result = from(bucket: "telegraf")
|> range(start: 2021-11-28T16:53:37.426Z, stop: 2021-11-29T16:53:37.426Z)
|> filter(fn: (r) => r["_measurement"] == "docker_container_blkio")
|> filter(fn: (r) => r["_field"] == "io_service_bytes_recursive_write" or r["_field"] == "io_service_bytes_recursive_read")
|> filter(fn: (r) => r["device"] == "total")
|> filter(fn: (r) => r["container_name"] == "mycontainer")
|> filter(fn: (r) => r["container_status"] == "running")
|> aggregateWindow(every: 5m0s, fn: mean, createEmpty: false)
|> derivative(unit: 1s, nonNegative: false)

column = result|> findColumn(fn: (key) => true, column: "_value")
resultX = if length(arr: column) > 0 then result else result
resultX|>yield()
```

While these alterations of the query produce results without an error:
```
result = from(bucket: "telegraf")
|> range(start: 2021-11-28T16:53:37.426Z, stop: 2021-11-29T16:53:37.426Z)
|> filter(fn: (r) => r["_measurement"] == "docker_container_blkio")
|> filter(fn: (r) => r["_field"] == "io_service_bytes_recursive_write" or r["_field"] == "io_service_bytes_recursive_read")
|> filter(fn: (r) => r["device"] == "total")
|> filter(fn: (r) => r["container_name"] == "mycontainer")
|> filter(fn: (r) => r["container_status"] == "running")
|> aggregateWindow(every: 5m0s, fn: mean, createEmpty: false)
// |> derivative(unit: 1s, nonNegative: false)

column = result|> findColumn(fn: (key) => true, column: "_value")
resultX = if length(arr: column) > 0 then result else result
resultX|>yield()
```
or
```
result = from(bucket: "telegraf")
|> range(start: 2021-11-28T16:53:37.426Z, stop: 2021-11-29T16:53:37.426Z)
|> filter(fn: (r) => r["_measurement"] == "docker_container_blkio")
|> filter(fn: (r) => r["_field"] == "io_service_bytes_recursive_write" or r["_field"] == "io_service_bytes_recursive_read")
|> filter(fn: (r) => r["device"] == "total")
|> filter(fn: (r) => r["container_name"] == "mycontainer")
|> filter(fn: (r) => r["container_status"] == "running")
// |> aggregateWindow(every: 5m0s, fn: mean, createEmpty: false)
|> derivative(unit: 1s, nonNegative: false)

column = result|> findColumn(fn: (key) => true, column: "_value")
resultX = if length(arr: column) > 0 then result else result
resultX|>yield()
```
or
```
result = from(bucket: "telegraf")
|> range(start: 2021-11-28T16:53:37.426Z, stop: 2021-11-29T16:53:37.426Z)
|> filter(fn: (r) => r["_measurement"] == "docker_container_blkio")
|> filter(fn: (r) => r["_field"] == "io_service_bytes_recursive_write" or r["_field"] == "io_service_bytes_recursive_read")
|> filter(fn: (r) => r["device"] == "total")
|> filter(fn: (r) => r["container_name"] == "mycontainer")
|> filter(fn: (r) => r["container_status"] == "running")
|> aggregateWindow(every: 5m0s, fn: mean, createEmpty: false)
|> derivative(unit: 1s, nonNegative: false)

column = result|> findColumn(fn: (key) => true, column: "_value")
resultX = result
resultX|>yield()
```

It works with other containers (selected by _container_name_) so the query per-se is o.k., but for this specific container it seems the data leads to the error.

__Environment info:__

* System info: Linux 4.19.67-rt24-gda7e8a4 aarch64
* InfluxDB version: InfluxDB 2.1.1 Server: 657e183 Frontend: cc65325
* Other relevant environment details: Using arm64v8/influxdb:2.1.1-alpine Docker image

__Logs:__
```
ts=2021-11-29T17:06:23.186588Z lvl=warn msg="internal error not returned to client" log_id=0Y6qp~t0000 handler=error_logger error="runtime error: invalid memory address or nil pointer dereference"
ts=2021-11-29T17:06:23.186431Z lvl=info msg="panic during program start" log_id=0Y6qp~t0000 service=storage-reads error="runtime error: invalid memory address or nil pointer dereference" stacktrace="goroutine 662 [running]:\nruntime/debug.Stack()\n\t/home/circleci/.tools/go/src/runtime/debug/stack.go:24 +0x88\ngithub.com/influxdata/influxdb/v2/query/control.(*Controller).executeQuery.func1(0x4005788780, 0x4001d08600)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/query/control/controller.go:457 +0x140\npanic({0xffffa3d6d840, 0xffffa54484b0})\n\t/home/circleci/.tools/go/src/runtime/panic.go:1038 +0x21c\ngithub.com/influxdata/flux/values.BuildObjectWithSize(0x0, 0x4005b6ecd0)\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/values/object.go:130 +0x378\ngithub.com/influxdata/flux/values.BuildObject(...)\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/values/object.go:100\ngithub.com/influxdata/flux/interpreter.(*Interpreter).doArguments(0x4005b536c0, {0xffffa41a8ec0, 0x400151c930}, 0x4005a90000, {0xffffa41e3188, 0x40093c1080}, {0x5, {0xffffa41725e0, 0x40003f6240}, 0xc}, ...)\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/interpreter/interpreter.go:737 +0x340\ngithub.com/influxdata/flux/interpreter.(*Interpreter).doCall(0x4005b536c0, {0xffffa41a8ec0, 0x400151c930}, 0x40017d7cb0, {0xffffa41e3188, 0x40093c1080})\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/interpreter/interpreter.go:664 +0x288\ngithub.com/influxdata/flux/interpreter.(*Interpreter).doExpression(0x4005b536c0, {0xffffa41a8ec0, 0x400151c930}, {0xffffa41b9590, 0x40017d7cb0}, {0xffffa41e3188, 0x40093c1080})\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/interpreter/interpreter.go:336 +0x13f4\ngithub.com/influxdata/flux/interpreter.(*Interpreter).doExpression(0x4005b536c0, {0xffffa41a8ec0, 0x400151c930}, {0xffffa41b9500, 0x40017d7c20}, {0xffffa41e3188, 0x40093c1080})\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/interpreter/interpreter.go:396 +0x1114\ngithub.com/influxdata/flux/interpreter.(*Interpreter).doExpression(0x4005b536c0, {0xffffa41a8ec0, 0x400151c930}, {0xffffa41b95d8, 0x4005a3bb20}, {0xffffa41e3188, 0x40093c1080})\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/interpreter/interpreter.go:451 +0xec\ngithub.com/influxdata/flux/interpreter.(*Interpreter).doStatement(0x4005b536c0, {0xffffa41a8ec0, 0x400151c930}, {0xffffa41b44b8, 0x4002af8960}, {0xffffa41e3188, 0x40093c1080})\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/interpreter/interpreter.go:171 +0x26c\ngithub.com/influxdata/flux/interpreter.(*Interpreter).doFile(0x4005b536c0, {0xffffa41a8ec0, 0x400151c930}, 0x4004f05300, {0xffffa41e3188, 0x40093c1080}, {0xffffa4156e00, 0x4002770b30})\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/interpreter/interpreter.go:111 +0x174\ngithub.com/influxdata/flux/interpreter.(*Interpreter).doPackage(0x4005b536c0, {0xffffa41a8ec0, 0x400151c930}, 0x4005a3ad20, {0xffffa41e3188, 0x40093c1080}, {0xffffa4156e00, 0x4002770b30})\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/interpreter/interpreter.go:94 +0x98\ngithub.com/influxdata/flux/interpreter.(*Interpreter).doRoot(0x4005b536c0, {0xffffa41a8ec0, 0x400151c930}, {0xffffa41aa190, 0x4005a3ad20}, {0xffffa41e3188, 0x40093c1080}, {0xffffa4156e00, 0x4002770b30})\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/interpreter/interpreter.go:84 +0x114\ngithub.com/influxdata/flux/interpreter.(*Interpreter).Eval(0x4005b536c0, {0xffffa41a8ec0, 0x400151c930}, {0xffffa41aa190, 0x4005a3ad20}, {0xffffa41e3188, 0x40093c1080}, {0xffffa4156e00, 0x4002770b30})\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/interpreter/interpreter.go:75 +0x6c\ngithub.com/influxdata/flux/runtime.(*runtime).Eval(0xffffaaed8f90, {0xffffa41a8ec0, 0x400151c930}, {0xffffa417be90, 0x40058cb960}, {0xffffa4172770, 0xffffaaf13c50}, {0x4002770a30, 0x2, 0x2})\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/runtime/runtime.go:119 +0x21c\ngithub.com/influxdata/flux/lang.(*AstProgram).getSpec(0x4001f0b2c0, {0xffffa41a8ec0, 0x400151c900}, 0x4001f0b3b0)\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/lang/compiler.go:447 +0x224\ngithub.com/influxdata/flux/lang.(*AstProgram).Start(0x4001f0b2c0, {0xffffa41a8ec0, 0x400151c840}, 0x4001f0b3b0)\n\t/home/circleci/go/pkg/mod/github.com/influxdata/flux@v0.139.0/lang/compiler.go:484 +0x18c\ngithub.com/influxdata/influxdb/v2/query/control.(*Controller).executeQuery(0x4001d08600, 0x4005788780)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/query/control/controller.go:480 +0x204\ngithub.com/influxdata/influxdb/v2/query/control.(*Controller).processQueryQueue(0x4001d08600)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/query/control/controller.go:438 +0x34\ngithub.com/influxdata/influxdb/v2/query/control.New.func1(0x4001d08600)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/query/control/controller.go:220 +0x54\ncreated by github.com/influxdata/influxdb/v2/query/control.New\n\t/home/circleci/go/src/github.com/influxdata/influxdb/query/control/controller.go:218 +0x858\n"
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the supplied Flux query on the reported InfluxDB version, then start with the stack-trace entry points in flux/values/object.go, flux/interpreter/interpreter.go, and query/control/controller.go. Trace why combining derivative() with the if expression reaches a nil object; done means the query no longer panics and returns a normal result or error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.