flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

golang deserialization in multi goroutine get panic[Golang1.14.4, linux, FlatBuffers 2.0]

Open JackyXiong opened this issue 5 years ago • 2 comments

I use golang to deserialize data. When one goroutine to deserialize, it's ok. But when more than one goroutine, it wil get panic.

Some traceback

panic: runtime error: slice bounds out of range [2630780038:161992]

goroutine 66 [running]:
github.com/google/flatbuffers/go.(*Table).GetVOffsetT(...)
	/go/pkg/mod/github.com/google/[email protected]+incompatible/go/table.go:134
github.com/google/flatbuffers/go.(*Table).Offset(0xc00059daf0, 0xc000010004, 0xc00059d910)
	/go/pkg/mod/github.com/google/[email protected]+incompatible/go/table.go:16 +0xed
defender/app/mlogfbs.(*Mlog).Tag(0xc00059daf0, 0x2, 0x14c)
	/opt/defender/app/mlogfbs/Mlog.go:41 +0x263

How to solve this?

JackyXiong avatar Sep 17 '21 03:09 JackyXiong

There's nothing in FlatBuffers itself that provides safe concurrent access, that is a matter for user code. For example concurrent serialization clearly doesn't work.

That said, de-serialization, with the source data being just a byte buffer, should generally be easy to make work. One thing to be careful of is accessor objects such as Table in your stack trace, which will be allocated, and sometimes re-used (depending on the API call) during de-serialization. You must make sure that these objects are not share between threads, and that only the source byte array is shared. Or you must make sure they are always freshly allocated.

Other than that, no idea. Hard to debug concurrency issues thru a GitHub issue.

aardappel avatar Sep 20 '21 19:09 aardappel

This issue is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.

github-actions[bot] avatar Mar 21 '22 20:03 github-actions[bot]