Open un000 opened 2 years ago
Looks like I found a reproducer(run it multiple times with -race
to see):
package tracer_test
import (
"sync"
"testing"
jsoniter "github.com/json-iterator/go"
)
func MarshalJSON(i any) (string, error) {
res, err := jsoniter.MarshalToString(i)
return res, err
}
func TestMarshalJSON(t *testing.T) {
m1 := map[int]any{1: 5, 5:44}
m2 := map[string]any{"a": "b", "c": "9"}
m3 := map[any]string{1: "6", "7": "8"}
wg := sync.WaitGroup{}
for i := 0; i < 1000; i++ {
wg.Add(3)
go func() {
defer wg.Done()
MarshalJSON(m1)
}()
go func() {
defer wg.Done()
MarshalJSON(m2)
}()
go func() {
defer wg.Done()
MarshalJSON(m3)
}()
}
wg.Wait()
}
==================
WARNING: DATA RACE
Read at 0x00c00005a0e0 by goroutine 13:
github.com/json-iterator/go.(*placeholderEncoder).Encode()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect.go:332 +0x38
github.com/json-iterator/go.(*numericMapKeyEncoder).Encode()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect_map.go:222 +0x126
github.com/json-iterator/go.(*dynamicMapKeyEncoder).Encode()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect_map.go:237 +0x116
github.com/json-iterator/go.(*mapEncoder).Encode()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect_map.go:263 +0x861
github.com/json-iterator/go.(*onePtrEncoder).Encode()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect.go:219 +0xa3
github.com/json-iterator/go.(*Stream).WriteVal()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect.go:98 +0x1f7
github.com/json-iterator/go.(*frozenConfig).MarshalToString()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/config.go:289 +0xe6
github.com/json-iterator/go.MarshalToString()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/adapter.go:44 +0x59
Previous write at 0x00c00005a0e0 by goroutine 10:
github.com/json-iterator/go.createEncoderOfType()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect.go:246 +0x198
github.com/json-iterator/go.encoderOfType()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect.go:227 +0x66
github.com/json-iterator/go.encoderOfMapKey()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect_map.go:133 +0x633
github.com/json-iterator/go.(*dynamicMapKeyEncoder).Encode()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect_map.go:237 +0xbb
github.com/json-iterator/go.(*mapEncoder).Encode()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect_map.go:263 +0x861
github.com/json-iterator/go.(*onePtrEncoder).Encode()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect.go:219 +0xa3
github.com/json-iterator/go.(*Stream).WriteVal()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/reflect.go:98 +0x1f7
github.com/json-iterator/go.(*frozenConfig).MarshalToString()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/config.go:289 +0xe6
github.com/json-iterator/go.MarshalToString()
/Users/un0/go/pkg/mod/github.com/json-iterator/go@v1.1.12/adapter.go:44 +0x59
same error
I have same error Version go: v1.15 Json-iterator v1.1.12
go 1.18 json-iterator v1.1.12 same error 一样的错误
六月份的问题,现在还没有解决吗?不准备解决了吗?
Hello, got an issue after deployment. My service restarted with a following panic:
The code
Env