consulthys / springbeat

Simple Beat for collecting metrics from Spring Boot apps
Other
27 stars 8 forks source link

Invalid memory address or nil pointer dereference error on runtime #2

Closed robin-maxxton closed 7 years ago

robin-maxxton commented 7 years ago

Hi,

Thanks for creating this MetricBeat module. It's a good base for getting the metrics from Spring into Elasticsearch

I tried to build ans run it but I keep getting the following error

2016/12/05 15:33:26.191965 springbeat.go:101: DBG  Metrics stats for url: http://192.168.252.178:50613
2016/12/05 15:33:26.201150 springbeat.go:107: DBG  Metrics stats detail: &{Mem:{Total:1570009 Free:632923} Processors:4 LoadAverage:-1 Uptime:{Total:18462144 Instance:18435802} Heap:{Total:3674112 Committed:1440768 Init:260096 Used:807844} NonHeap:{Total:0 Committed:131136 Init:2496 Used:129241} Threads:{Total:50 TotalStarted:138 Peak:52 Daemon:34} Classes:{Total:16194 Loaded:16194 Unloaded:0} GC:{Scavenge:{Count:22 Time:486} Marksweep:{Count:3 Time:327}} Http:{SessionsMax:-1 SessionsActive:0} DataSource:{PrimaryActive:0 PrimaryUsage:0} GaugeResponse:{Actuator:0 Autoconfig:0 Beans:0 Configprops:0 Dump:0 Env:0 Health:0 Info:0 Root:0 Trace:0 Unmapped:0} Status:{TWO00:{Actuator:0 Autoconfig:0 Beans:0 Configprops:0 Dump:0 Env:0 Health:0 Info:0 Root:0 Trace:0}}}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x46a253]

goroutine 46 [running]:
panic(0x8a1a20, 0xc4200100b0)
        /usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/consulthys/springbeat/beater.(*Springbeat).Run.func1(0xc4201903f0, 0xc420183600)
        /root/work/src/github.com/consulthys/springbeat/beater/springbeat.go:116 +0xc83
created by github.com/consulthys/springbeat/beater.(*Springbeat).Run
        /root/work/src/github.com/consulthys/springbeat/beater/springbeat.go:152 +0x9d

It always occurs after getting the metrics info from the Spring boot application, and stops the daemon with a fatal error

Did some research on the Golang GitHub page and found out that this is a known issue which can be solved by removing the pkg folder(s) and rebuilding everything. https://groups.google.com/forum/#!topic/golang-dev/kkVa_W1IenE

The odd thing is that this doesn't help fix the error. I also tried it on a fresh Ubuntu installation, but it still gives throws the same error.

Steps I followed

mkdir -p ${GOPATH}/src/github.com/consulthys
cd ${GOPATH}/src/github.com/consulthys
git clone https://github.com/consulthys/springbeat
cd springbeat
make
./springbeat -c springbeat.yml -e -d "*"

Please note that I added the /src folder before the github.com folder. Otherwise I was unable to build the code (please refer to the documentation that has the same folder structure https://www.elastic.co/guide/en/beats/libbeat/current/newbeat-generate.html)

Any idea how this issue can be fixed? Thanks in advance

robin-maxxton commented 7 years ago

Managed to fix the issue by adding bt.client = b.Publisher.Connect() to springbeat.go on line 85 https://github.com/consulthys/springbeat/blob/master/beater/springbeat.go#L85

I guess this became mandatory with the release of 5.x.

consulthys commented 7 years ago

Thanks for reporting this. It's weird that I didn't see the same issue. I'll check out your PR and merge it asap.