Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error: invalid memory address or nil pointer dereference #872

Closed
opsnull opened this issue Sep 6, 2016 · 5 comments
Closed
Assignees
Labels
Milestone

Comments

@opsnull
Copy link

opsnull commented Sep 6, 2016

kapacitor RPM info:

Name : kapacitor
Arch : x86_64
Version : 0.13.1
Release : 1
Size : 41 M
Repo : installed
From repo : /kapacitor-0.13.1.x86_64
Summary : Time series data processing engine
URL : github.com/influxdata/kapacitor
License : MIT
Description : Time series data processing engine

TICKscript

var ping_statistic = stream
        |from()
                .database('netbench')
                .retentionPolicy('default')
                .measurement('ping_statistic')
                .groupBy('hostName', 'isp', 'province')
        |window()
                .period(1m)
                .every(1m)

var avgLoss = ping_statistic
        |last('avgLoss')
                .as('avgLoss')

avgLoss
        |alert()
                .crit(lambda: "avgLoss" > 5)
                .log('/tmp/alerts_loss.log')

kapacitor log

[httpd] 2016/09/06 23:38:04 I! 10.160.109.152 - - [06/Sep/2016:23:38:04 +0800] GET /kapacitor/v1/tasks/alert_netbench HTTP/1.1 200 5974 - curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2 e7153ecb-7447-11e6-8014-000000000000 6.812757ms
[alert_netbench:last3] 2016/09/06 23:39:03 E! failed to aggregate batch: field avgLoss missing from point cannot aggregate

panic message:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x5f5375]

goroutine 184 [running]:
panic(0xca0ec0, 0xc820010100)
/usr/local/go/src/runtime/panic.go:481 +0x3e6
github.com/influxdata/kapacitor/vendor/github.com/influxdata/influxdb/influxql.(_FloatFuncReducer).Emit(0xc8202d5490, 0x0, 0x0, 0x0)
/root/go/src/github.com/influxdata/kapacitor/vendor/github.com/influxdata/influxdb/influxql/functions.gen.go:68 +0xa5
github.com/influxdata/kapacitor.(_floatPointEmitter).EmitPoint(0xc820b40510, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/root/go/src/github.com/influxdata/kapacitor/influxql.gen.go:166 +0x78
github.com/influxdata/kapacitor.(_InfluxQLNode).emit(0xc8200e5000, 0x7f3596286140, 0xc820b404e0, 0x0, 0x0)
/root/go/src/github.com/influxdata/kapacitor/influxql.go:185 +0x90
github.com/influxdata/kapacitor.(_InfluxQLNode).runBatchInfluxQL(0xc8200e5000, 0x0, 0x0)
/root/go/src/github.com/influxdata/kapacitor/influxql.go:162 +0x62c
github.com/influxdata/kapacitor.(_InfluxQLNode).runInfluxQLs(0xc8200e5000, 0x0, 0x0, 0x0, 0x0, 0x0)
/root/go/src/github.com/influxdata/kapacitor/influxql.go:42 +0x83
github.com/influxdata/kapacitor.(_InfluxQLNode).(github.com/influxdata/kapacitor.runInfluxQLs)-fm(0x0, 0x0, 0x0, 0x0, 0x0)
/root/go/src/github.com/influxdata/kapacitor/influxql.go:33 +0x4c
github.com/influxdata/kapacitor.(_node).start.func1(0xc8200e5000, 0x0, 0x0, 0x0)
/root/go/src/github.com/influxdata/kapacitor/node.go:128 +0x7f
created by github.com/influxdata/kapacitor.(_node).start
/root/go/src/github.com/influxdata/kapacitor/node.go:129 +0x53

@nathanielc
Copy link
Contributor

This has been fixed in the 1.0.0 version See #510

@opsnull
Copy link
Author

opsnull commented Sep 9, 2016

@nathanielc , I have upgraded to v1.0.0, but still panic!

@opsnull
Copy link
Author

opsnull commented Sep 9, 2016

@nathanielc , I have added debug code to kapacitor:

diff --git a/influxql.gen.go b/influxql.gen.go
index c8720a3..7cd67f9 100644
--- a/influxql.gen.go
+++ b/influxql.gen.go
@@ -163,7 +163,17 @@ type floatPointEmitter struct {
        byName           bool
 }

-func (e *floatPointEmitter) EmitPoint() (models.Point, error) {
+func (e *floatPointEmitter) EmitPoint() (point models.Point, err error) {
+       defer func(){
+               if r := recover(); r != nil {
+                       fmt.Printf("\npanic: %v\n", r)
+                       fmt.Printf("e.baseReduceContext: %#v\n", e.baseReduceContext)
+                       fmt.Printf("\ne.emitter: %#v\n", e.emitter)
+
+                       point = models.Point{}
+                       err = ErrEmptyEmit
+               }
+       }()

When panic, the output is following:

panic: runtime error: invalid memory address or nil pointer dereference
e.baseReduceContext: kapacitor.baseReduceContext{as:"avgLoss", field:"avgLoss", name:"ping_statistic", group:"hostName=亦庄BGP,isp=联通,province=海南", dimensions:models.Dimensions{ByName:false, TagNames:[]string{"hostName", "isp", "province"}}, tags:models.Tags{"hostName":"亦庄BGP", "isp":"联通", "province":"海南"}, time:time.Time{sec:63609014914, nsec:106981616, loc:(*time.Location)(0xf9cf00)}, pointTimes:false, topBottomInfo:(*pipeline.TopBottomCallInfo)(nil)}

e.emitter: &influxql.FloatFuncReducer{prev:(*influxql.FloatPoint)(nil), fn:(influxql.FloatReduceFunc)(0x5c4c90)}

e.emitter.prev is nil, so in influxdb/influxql/functions.gen.go line 72~75:

// Emit emits the point that was generated when reducing the points fed in with AggregateFloat.
func (r *FloatFuncReducer) Emit() []FloatPoint {
    return []FloatPoint{*r.prev}
}

executing *r.prev will panic.

@nathanielc nathanielc reopened this Sep 9, 2016
@nathanielc nathanielc added the bug label Sep 9, 2016
@nathanielc nathanielc added this to the v1.1.0 milestone Sep 9, 2016
@nathanielc
Copy link
Contributor

@geekard Thanks for the detailed write up. Can you also share the dataset your are using with the TICKscript to cause the panic? I have been unable to reproduce the panic locally.

I see that the panic happens because of the nil r.prev, but I haven't been able to figure out how r.prev is nil. In the code EmitPoint is only called after AggregateBatch, and AggregateBatch sets r.prev to an non nil value. Obviously there is something I am missing ;), so the dataset should help straighten things out. Thanks again.

@nathanielc nathanielc modified the milestones: Unplanned, v1.1.0 Oct 25, 2016
nathanielc added a commit that referenced this issue Jan 13, 2017
@nathanielc nathanielc self-assigned this Jan 13, 2017
@garbamoussa
Copy link

Hi
I use UDF to test unit root in time series but I have this error :

18-11-01T08%3A37%3A00Z%27+AND+time+%3C+%272018-11-08T08%3A37%3A00Z%27 HTTP/1.1" 200 40526 "-" "KapacitorInfluxDBClient" 758f027a-e331-11e8-8531-000000000000 82350
Nov 8 09:37:00 python2[24258]: 2018-11-08 09:37:00,132 INFO:root: Begin batch
Nov 8 09:37:00 influxd[16026]: [httpd] ::1 - - [08/Nov/2018:09:37:00 +0100] "POST /write?db=telegraf HTTP/1.1" 204 0 "-" "telegraf" 75bd06b3-e331-11e8-8532-000000000000 19549
Nov 8 09:37:01 python2[24258]: 2018-11-08 09:37:01,892 INFO:root: SIZE OF INPUT: 7609
Nov 8 09:37:01 python2[24258]: RESULTS OF KPSS TEST !!!
Nov 8 09:37:01 python2[24258]: 2018-11-08 09:37:01,893 DEBUG:root: TEST_KPSS KPSS Stationarity Test Results
Nov 8 09:37:01 python2[24258]: =====================================
Nov 8 09:37:01 python2[24258]: Test Statistic 0.003
Nov 8 09:37:01 python2[24258]: P-value 0.999
Nov 8 09:37:01 python2[24258]: Lags 36
Nov 8 09:37:01 python2[24258]: -------------------------------------
Nov 8 09:37:01 python2[24258]: Trend: Constant and Linear Time Trend
Nov 8 09:37:01 python2[24258]: Critical Values: 0.22 (1%), 0.15 (5%), 0.12 (10%)
Nov 8 09:37:01 python2[24258]: Null Hypothesis: The process is weakly stationary.
Nov 8 09:37:01 python2[24258]: Alternative Hypothesis: The process contains a unit root.
Nov 8 09:37:01 python2[24258]: STATIONNAIRE !!!
Nov 8 09:37:01 python2[24258]: 2018-11-08 09:37:01,898 INFO:root: ending batch
Nov 8 09:37:02 influxd[16026]: [httpd] ::1 - - [08/Nov/2018:09:37:02 +0100] "POST /write?db=telegraf HTTP/1.1" 204 0 "-" "telegraf" 76d1b997-e331-11e8-8533-000000000000 143788
Nov 8 09:37:02 influxd[16026]: [httpd] ::1 - - [08/Nov/2018:09:37:02 +0100] "POST /write?db=telegraf HTTP/1.1" 204 0 "-" "telegraf" 76ead44d-e331-11e8-8534-000000000000 86760
Nov 8 09:37:02 influxd[16026]: [httpd] ::1 - - [08/Nov/2018:09:37:02 +0100] "POST /write?db=telegraf HTTP/1.1" 204 0 "-" "telegraf" 76fb4792-e331-11e8-8535-000000000000 70790
Nov 8 09:37:09 chronograf[16176]: time="2018-11-08T09:37:09+01:00" level=info msg="Response: OK" component=server method=GET remote_addr="192.168.2.72:52272" response_time="38.098µs" status=200
Nov 8 09:37:10 influxd[16026]: [httpd] ::1 - - [08/Nov/2018:09:37:10 +0100] "POST /write?db=telegraf HTTP/1.1" 204 0 "-" "telegraf" 7bb2f6b2-e331-11e8-8536-000000000000 68416
Nov 8 09:37:13 kapacitord[364]: panic: runtime error: invalid memory address or nil pointer dereference
Nov 8 09:37:13 kapacitord[364]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x197b2a2]
Nov 8 09:37:13 kapacitord[364]: goroutine 19054 [running]:
Nov 8 09:37:13 kapacitord[364]: github.com/influxdata/kapacitor/udf.(*Server).handleResponse(0xc4208df1e0, 0xc4204e2080, 0x0, 0x0)
Nov 8 09:37:13 kapacitord[364]: #11/root/go/src/github.com/influxdata/kapacitor/udf/server.go:740 +0xb62
Nov 8 09:37:13 kapacitord[364]: github.com/influxdata/kapacitor/udf.(*Server).readData(0xc4208df1e0, 0x0, 0x0)
Nov 8 09:37:13 kapacitord[364]: #11/root/go/src/github.com/influxdata/kapacitor/udf/server.go:658 +0x98
Nov 8 09:37:13 kapacitord[364]: github.com/influxdata/kapacitor/udf.(*Server).Start.func2(0xc4208df1e0)
Nov 8 09:37:13 kapacitord[364]: #11/root/go/src/github.com/influxdata/kapacitor/udf/server.go:165 +0x2f
Nov 8 09:37:13 kapacitord[364]: created by github.com/influxdata/kapacitor/udf.(*Server).Start
Nov 8 09:37:13 kapacitord[364]: #11/root/go/src/github.com/influxdata/kapacitor/udf/server.go:164 +0x167
Nov 8 09:37:13 systemd[1]: kapacitor.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Nov 8 09:37:13 chronograf[16176]: 2018/11/08 09:37:13 httputil: ReverseProxy read error during body copy: unexpected EOF
Nov 8 09:37:13 chronograf[16176]: time="2018-11-08T09:37:13+01:00" level=info msg="Response: OK" component=server method=GET remote_addr="192.168.2.72:59280" response_time=8m29.61734239s status=200
Nov 8 09:37:13 chronograf[16176]: 2018/11/08 09:37:13 httputil: ReverseProxy read error during body copy: unexpected EOF
Nov 8 09:37:13 chronograf[16176]: time="2018-11-08T09:37:13+01:00" level=info msg="Response: OK" component=server method=GET remote_addr="192.168.2.72:60114" response_time=5m29.768058523s status=200
Nov 8 09:37:13 chronograf[16176]: 2018/11/08 09:37:13 httputil: ReverseProxy read error during body copy: unexpected EOF
Nov 8 09:37:13 chronograf[16176]: time="2018-11-08T09:37:13+01:00" level=info msg="Response: OK" component=server method=GET remote_addr="192.168.2.72:58694" response_time=2m10.531370173s status=200
Nov 8 09:37:13 python2[24258]: 2018-11-08 09:37:13,335 INFO:root: Agent finished connection 19
Nov 8 09:37:13 systemd[1]: kapacitor.service: Unit entered failed state.
Nov 8 09:37:13 systemd[1]: kapacitor.service: Failed with result 'exit-code'.
Nov 8 09:37:13 systemd[1]: kapacitor.service: Service hold-off time over, scheduling restart.
Any help is welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants