bytedance / sonic

A blazingly fast JSON serializing & deserializing library
Apache License 2.0
6.71k stars 333 forks source link

panic:concurrent map iteration and map write #541

Closed iwanlebron closed 10 months ago

iwanlebron commented 10 months ago

2023-10-22 15:35:43-------------------------------- fatal error: concurrent map iteration and map write

goroutine 991 [running]: github.com/bytedance/sonic/internal/encoder.iteratorNext(0xc003200c18?) /go/pkg/mod/github.com/bytedance/sonic@v1.10.2/internal/encoder/mapiter.go:150 +0xae encode_*sys.Message() ?:0 +0x15fc github.com/bytedance/sonic/internal/encoder.encodeTypedPointer(0xc003200c18, 0x2678de0, 0xc0041ebb48, 0x7fd86b654228?, 0x0) /go/pkg/mod/github.com/bytedance/sonic@v1.10.2/internal/encoder/primitives.go:83 +0x1be github.com/bytedance/sonic/internal/encoder.encodeInto(0xc003200c18, {0x2678de0, 0xc0024ee7e0}, 0xc0001602c0?) /go/pkg/mod/github.com/bytedance/sonic@v1.10.2/internal/encoder/encoder.go:225 +0xe5 github.com/bytedance/sonic/internal/encoder.Encode({0x2678de0, 0xc0024ee7e0}, 0x7fd8b294d3c8?) /go/pkg/mod/github.com/bytedance/sonic@v1.10.2/internal/encoder/encoder.go:182 +0xcf github.com/bytedance/sonic.frozenConfig.Marshal(...) /go/pkg/mod/github.com/bytedance/sonic@v1.10.2/sonic.go:86 github.com/bytedance/sonic.Marshal(...) /go/pkg/mod/github.com/bytedance/sonic@v1.10.2/api.go:153

liuq19 commented 10 months ago

could you add -race in tests? There may be a data-race problem

iwanlebron commented 10 months ago

this is an accidental phenomenon that is difficult to reproduce

AsterDY commented 10 months ago

go build -race can show more detailed trace. In general, it is introduced by user pass map between goroutine and use them concurrently, which has no relation with sonic