src-d / beanstool

Dependency free beanstalkd admin tool
MIT License
155 stars 32 forks source link

Error when filtering stats by --tubes #17

Open cpascu opened 7 years ago

cpascu commented 7 years ago

Hi!

I'm trying to filter the stats output by a list of tubes and am getting the following error. Initially I was listing several tubes separated by commas but I realised the same error occurs even with just a single tube.

`beanstool stats --host=xxx.xxx.xxx.xxx:11301 --tubes=dispatcher-fast panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x0 pc=0x46664f]

goroutine 1 [running]: github.com/src-d/beanstool/cli.(StatsCommand).buildLineFromTubeStats(0xc8200126c0, 0x6316d8, 0x7, 0x0, 0x0, 0x0, 0x0) /Users/mcuadros/workspace/go/src/github.com/src-d/beanstool/cli/stats.go:76 +0x8f github.com/src-d/beanstool/cli.(StatsCommand).PrintStats(0xc8200126c0, 0x0, 0x0) /Users/mcuadros/workspace/go/src/github.com/src-d/beanstool/cli/stats.go:58 +0x1b5 github.com/src-d/beanstool/cli.(StatsCommand).Execute(0xc8200126c0, 0xc820013170, 0x0, 0x3, 0x0, 0x0) /Users/mcuadros/workspace/go/src/github.com/src-d/beanstool/cli/stats.go:36 +0x74 github.com/jessevdk/go-flags.(Parser).ParseArgs(0xc820078190, 0xc82000a1d0, 0x3, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0) /Users/mcuadros/workspace/go/src/github.com/jessevdk/go-flags/parser.go:301 +0xa16 github.com/jessevdk/go-flags.(*Parser).Parse(0xc820078190, 0x0, 0x0, 0x0, 0x0, 0x0) /Users/mcuadros/workspace/go/src/github.com/jessevdk/go-flags/parser.go:175 +0x9b main.main() /Users/mcuadros/workspace/go/src/github.com/src-d/beanstool/beanstool.go:21 +0x6d4`

ramkumar-kr commented 6 years ago

Hi, I was able to reproduce the issue as well.

Backtrace

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x116d069]

goroutine 1 [running]:
github.com/src-d/beanstool/cli.(*StatsCommand).buildLineFromTubeStats(0xc000080690, 0x11d0e1c, 0x7, 0x0, 0x134c4a0, 0x0, 0xc0000b21e0)
    /Users/ramkumar/go/src/github.com/src-d/beanstool/cli/stats.go:78 +0xd9
github.com/src-d/beanstool/cli.(*StatsCommand).PrintStats(0xc000080690, 0x0, 0x0)
    /Users/ramkumar/go/src/github.com/src-d/beanstool/cli/stats.go:57 +0x277
github.com/src-d/beanstool/cli.(*StatsCommand).Execute(0xc000080690, 0xc000081140, 0x0, 0x3, 0xc000080690, 0x1)
    /Users/ramkumar/go/src/github.com/src-d/beanstool/cli/stats.go:36 +0x62
github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc0000b0230, 0xc0000880d0, 0x3, 0x3, 0x100d3c8, 0x30, 0x11b2140, 0xc00009e640, 0xc0000c0380)
    /Users/ramkumar/go/src/github.com/jessevdk/go-flags/parser.go:333 +0x80e
github.com/jessevdk/go-flags.(*Parser).Parse(0xc0000b0230, 0x11d0684, 0x4, 0x11d7609, 0x23, 0x0)
    /Users/ramkumar/go/src/github.com/jessevdk/go-flags/parser.go:190 +0x71
main.main()
    /Users/ramkumar/go/src/github.com/src-d/beanstool/beanstool.go:26 +0x43f
exit status 2

I tried to debug this and was able to figure out this issue and a fix.

TheGetStats function returns only the stats of the tubes mentioned when the --tubes argument is passed. However, in line 54 of stats.go, you are trying to print stats for the default tube as well. This results in the nil pointer dereference error.

To fix this, I removed the render statement and the if statement inside the for loop (line 58) and things seem to work fine.

I have created a pull request with the fix.