tsenart / vegeta

HTTP load testing tool and library. It's over 9000!
http://godoc.org/github.com/tsenart/vegeta/lib
MIT License
23.5k stars 1.36k forks source link

func (*Histogram) Add() can panic due to index out of range error #186

Closed vendion closed 8 years ago

vendion commented 8 years ago

Trying to use the Histogram support in the vegeta library and calling func (h *Histogram) Add(r *Result) results in a panic due to an index out of range error.

Here is the section of my code where I'm calling func (a *Attacker) Attack and later func (h *Histogram) Add(r *Result):

var metrics vegeta.Metrics
var results vegeta.Results
var histogram vegeta.Histogram
for res := range attacker.Attack(targeter, opts.rate, duration) {
    metrics.Add(res)
    results.Add(res)
    histrogram.Add(res)
}
metrics.Close()
results.Close()

When the above code is executed this is the stacktrace generated:

panic: runtime error: index out of range

goroutine 1 [running]:
panic(0x401e40, 0xc82000a0c0)
        /usr/local/go/src/runtime/panic.go:481 +0x3e6
biokdf-bench/vendor/github.com/tsenart/vegeta/lib.(*Histogram).Add(0xc8201120c0, 0xc820148460)
        /Users/vendion/gocode/src/biokdf-bench/vendor/github.com/tsenart/vegeta/lib/histogram.go:35 +0x13d
main.runAttack(0xc820100098, 0x4, 0xc8201000a0, 0xf, 0x0, 0xc820112000, 0x3, 0x4)
        /Users/vendion/gocode/src/biokdf-bench/main.go:86 +0x705
main.main()
        /Users/vendion/gocode/src/biokdf-bench/main.go:55 +0x1f5

in my code main.go:86 is histogram.Add(res). Digging through the program with Delve, it looks like the panic is caused by this line https://github.com/tsenart/vegeta/blob/master/lib/histogram.go#L35. This was tested with go version go1.6.2 darwin/amd64

tsenart commented 8 years ago

You need to define the buckets of the Histogram in order to use it. Have a look at the tests: https://github.com/tsenart/vegeta/blob/master/lib/histogram_test.go#L11

vendion commented 8 years ago

Thanks that is exactly what I was missing!