panic: runtime error: index out of range [recovered]
sundy-li opened this issue · comments
sundyli commented
Version:
4864f0c
BugStrace:
panic: runtime error: index out of range [recovered]
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x7a4933]
goroutine 1182 [running]:
MYGOPATH/src/my_package.Write.func1(0xc000723400, 0xc01968fed0)
MYGOPATH/src/my_package.go:106 +0xa3
panic(0xc2f480, 0x15a78d0)
/usr/local/go/src/runtime/panic.go:513 +0x1b9
github.com/valyala/fastjson.(*Object).unescapeKeys(0xc000124000)
MYGOPATH/src/github.com/valyala/fastjson/parser.go:488 +0xec
github.com/valyala/fastjson.(*Object).Get(0xc000124000, 0xc00072e5c0, 0x5, 0xc019d86020)
MYGOPATH/src/github.com/valyala/fastjson/parser.go:515 +0x3e
github.com/valyala/fastjson.(*Value).Get(0xc000124000, 0xc01968fbb0, 0x1, 0x1, 0x10)
MYGOPATH/src/github.com/valyala/fastjson/parser.go:686 +0x84
github.com/valyala/fastjson.(*Value).GetStringBytes(0xc000124000, 0xc01968fbb0, 0x1, 0x1, 0x41fd08, 0x10, 0xbe4980)
MYGOPATH/src/github.com/valyala/fastjson/parser.go:816 +0x4d
sundyli commented
Sorry, I didn't print the log string, I just use it for production and it panics.
Aliaksandr Valialkin commented
This looks like data race - concurrent thread uses the same Parser
for parsing another data. This leads to inconsistency between the initial length of o.kvs
passed to range
and the actual length of o.kvs
inside the loop where it panics:
for i := range o.kvs {
kv := &o.kvs[i] // <- panic on this line is possible only on data race described above
kv.k = unescapeStringBestEffort(kv.k)
}
Parser
cannot be used from concurrent goroutines. See Parser documentation for details.
Go provides data race detector for determining the data races in running programs. See https://golang.org/doc/articles/race_detector.html .