bosun-monitor / bosun

Time Series Alerting Framework
http://bosun.org
MIT License
3.4k stars 495 forks source link

Segfault occurs when non-json data is received from a .HTTPGetJSON call in a template #2121

Closed theblazehen closed 4 years ago

theblazehen commented 7 years ago
panic: runtime error: invalid memory address or nil pointer dereference [recovered] 
        panic: runtime error: invalid memory address or nil pointer dereference 
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x91ec66] 
goroutine 548915 [running]: 
panic(0xf2f020, 0xc420010060) 
        /usr/local/go/src/runtime/panic.go:500 +0x1a1 
text/template.errRecover(0xc42021b5d8) 
        /usr/local/go/src/text/template/exec.go:140 +0x2ad 
panic(0xf2f020, 0xc420010060) 
        /usr/local/go/src/runtime/panic.go:458 +0x243 
bosun.org/vendor/github.com/jmoiron/jsonq.(*JsonQuery).Array(0x0, 0xc4317ffa00, 0x2, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0) 
        /go/src/bosun.org/vendor/github.com/jmoiron/jsonq/jsonq.go:136 +0x26 
reflect.Value.call(0x1010f80, 0xc43182ccf8, 0x293, 0x108f3db, 0x4, 0xc431e8ac00, 0x1, 0x2, 0x18a5060, 0xf38ac0, ...) 
        /usr/local/go/src/reflect/value.go:434 +0x5c8 
reflect.Value.Call(0x1010f80, 0xc43182ccf8, 0x293, 0xc431e8ac00, 0x2, 0x2, 0x189f420, 0xc430888700, 0xecce60) 
        /usr/local/go/src/reflect/value.go:302 +0xa4 
text/template.(*state).evalCall(0xc42021b558, 0x105ff80, 0xc421656850, 0x16, 0x1010f80, 0xc43182ccf8, 0x293, 0x189f000, 0xc430888580, 0xc42b7eaadf, ...) 
        /usr/local/go/src/text/template/exec.go:658 +0x530 
text/template.(*state).evalField(0xc42021b558, 0x105ff80, 0xc421656850, 0x16, 0xc42b7eaadf, 0x5, 0x189f000, 0xc430888580, 0xc430888780, 0x3, ...)
kylebrandt commented 7 years ago

When I added this I wasn't really thinking about error handling in templates. There is error handling now, so what we would need is to refactor this (and probably make something like the library underneath it) in a way that fits with our error handling in templates.

For now I'm adding need documentation since we should add an admonition about this function.