0

My program crashes with the error below. Usually I could find the lines of my code causing the panic but now there is only Go specific code. Is there any option to increase the size of the lines/stack traced (i.e. up code causing the panic)?

panic: runtime error: slice bounds out of range

goroutine 1354 [running]:
io.copyBuffer(0x4c9da60, 0xc420142c88, 0x4c9b5a0, 0xc4206e1c80, 0xc42068a000, 0x8000, 0x8000, 0xc42001b370, 0xc42001b300, 0x47846a0)
    /usr/local/Cellar/go/1.9/libexec/src/io/io.go:394 +0x340
io.Copy(0x4c9da60, 0xc420142c88, 0x4c9b5a0, 0xc4206e1c80, 0xc42024533e, 0xc4202c5c80, 0x4916258)
    /usr/local/Cellar/go/1.9/libexec/src/io/io.go:362 +0x68
os/exec.(*Cmd).stdin.func1(0xc420291c28, 0xc4206d1d80)
    /usr/local/Cellar/go/1.9/libexec/src/os/exec/exec.go:219 +0x55
os/exec.(*Cmd).Start.func1(0xc420136580, 0xc4206f94e0)
    /usr/local/Cellar/go/1.9/libexec/src/os/exec/exec.go:380 +0x27
created by os/exec.(*Cmd).Start
    /usr/local/Cellar/go/1.9/libexec/src/os/exec/exec.go:379 +0x646

OS

$ go version
go version go1.9 darwin/amd64
mike
  • 533
  • 1
  • 7
  • 24
  • Add some logging inside your goroutines. `log.Println()` – reticentroot Sep 28 '17 at 20:28
  • How are you setting up your `exec.Cmd`? Have you checked for race conditions? – JimB Sep 28 '17 at 20:29
  • @reticentroot the program is quite large so adding some logging inside go routines is not really feasible...I already have logging but I can't figure out where the panic occours. – mike Sep 28 '17 at 20:36
  • @JimB I did...but the program is supposed to be POC so there are very few tests. Is it possible to check race condition without go test --race ? – mike Sep 28 '17 at 20:37
  • @reticentroot you realize that's a runtime panic, right? "slice bounds out of range" – mike Sep 28 '17 at 20:38
  • It's runtime panic you're right my bad, are you aware that adding logging as your building anything will save you this headache in the future? If you can't add logging then you'll have to work backwards from the caller. "jump in" lots of IDEs have a jump feature – reticentroot Sep 28 '17 at 20:40
  • The top of your stack is pointing in this file https://golang.org/src/io/io.go?s=12961:13039#L359 specifically this line `nw, ew := dst.Write(buf[0:nr])` Where are you calling `Copy` or `CopyBuffer` ? Where ever you are calling that that's the issue.. `nr == src` so what ever buffer you are passing into `io.Copy` is to small – reticentroot Sep 28 '17 at 20:45
  • @reticentroot the program is stateful with a lot of io.Readers (passed to *exec.Cmd). I have some clues where to look but thought there might be an option to increase the stack traced and save some time hunting for this bug thus the SO question. – mike Sep 28 '17 at 20:48
  • try https://stackoverflow.com/questions/19094099/how-to-dump-goroutine-stacktraces – reticentroot Sep 28 '17 at 20:51
  • @mike: you can always use the `-race` flag, it's not just for tests. That panic is in a place that literally can't happen, so memory corruption would be my first guess. – JimB Sep 28 '17 at 20:51
  • I'm pretty sure everyone is looking in the wrong place. The goroutine that is panicking is the goroutine that copies from `(*Cmd).Stdin` to the running command's standard input pipe. It is very likely that something is wrong with the `io.Reader` passed to the command as its standard input. – Milo Christiansen Sep 29 '17 at 08:24
  • @MiloChristiansen you were right... I found the issue. It was that my io.Reader lied about the bytes read(i.e. it provided a higher value than it actually read. – mike Sep 29 '17 at 10:01

0 Answers0