goccy / go-json

Fast JSON encoder/decoder compatible with encoding/json for Go
MIT License
3.11k stars 148 forks source link

Updating libraries in a package with benchmarks to eliminate panic on go versions 1.18 and higher #508

Open sanekkurt opened 6 months ago

sanekkurt commented 6 months ago

When running benchmarks on version go 1.18 and higher, the tests panicked Benchmark_Encode_MapInterface_JsonIter and Benchmark_Encode_MapInterface_Jettison with the message:

fatal error: fault
[signal SIGSEGV: segmentation violation code=0x1 addr=0x808085a175a75 pc=0x757e0]

goroutine 1377 [running]:
runtime.throw({0x36e2c4?, 0x1f7f4?})
  /usr/local/go/src/runtime/panic.go:992 +0x50 fp=0x4000054ab0 sp=0x4000054a80 pc=0x46590
runtime.sigpanic()
  /usr/local/go/src/runtime/signal_unix.go:825 +0x1a4 fp=0x4000054ae0 sp=0x4000054ab0 pc=0x5d744
aeshashbody()
  /usr/local/go/src/runtime/asm_arm64.s:885 +0x2d0 fp=0x4000054af0 sp=0x4000054af0 pc=0x757e0
runtime.mapiternext(0x4000013d40)
  /usr/local/go/src/runtime/map.go:934 +0x2c4 fp=0x4000054b60 sp=0x4000054af0 pc=0x202c4
runtime.mapiterinit(0x4000054c08?, 0x1b3ec?, 0x4000054c18?)
  /usr/local/go/src/runtime/map.go:861 +0x2f4 fp=0x4000054b90 sp=0x4000054b60 pc=0x1ffc4
reflect.mapiterinit(0x4000054c48?, 0x7d3d4?, 0x4000054c98?)
  /usr/local/go/src/runtime/map.go:1373 +0x20 fp=0x4000054bc0 sp=0x4000054b90 pc=0x727a0
github.com/modern-go/reflect2.(*UnsafeMapType).UnsafeIterate(...)
  /go/pkg/mod/github.com/modern-go/reflect2@v1.0.1/unsafe_map.go:112
github.com/json-iterator/go.(*sortKeysMapEncoder).Encode(0x40004c6f90, 0x40000da338, 0x4000a40f00)
  /go/pkg/mod/github.com/json-iterator/go@v1.1.10/reflect_map.go:291 +0x244 fp=0x4000054d40 sp=0x4000054bc0 pc=0x291014
github.com/json-iterator/go.(*onePtrEncoder).Encode(0x4000c3c160, 0x40004c6ab0, 0x4000013d40?)
  /go/pkg/mod/github.com/json-iterator/go@v1.1.10/reflect.go:219 +0x8c fp=0x4000054d80 sp=0x4000054d40 pc=0x28988c
github.com/json-iterator/go.(*Stream).WriteVal(0x4000a40f00, {0x31d600, 0x40004c6ab0})
  /go/pkg/mod/github.com/json-iterator/go@v1.1.10/reflect.go:98 +0x174 fp=0x4000054e00 sp=0x4000054d80 pc=0x288c44
github.com/json-iterator/go.(*frozenConfig).Marshal(0x4000014be0, {0x31d600, 0x40004c6ab0})
  /go/pkg/mod/github.com/json-iterator/go@v1.1.10/config.go:299 +0x88 fp=0x4000054ea0 sp=0x4000054e00 pc=0x281028
benchmark.Benchmark_Encode_MapInterface_JsonIter(0x400014c900)
  /root/go-json/benchmarks/encode_test.go:590 +0x25c fp=0x4000054f10 sp=0x4000054ea0 pc=0x2e9a9c
testing.(*B).runN(0x400014c900, 0x1)
  /usr/local/go/src/testing/benchmark.go:193 +0x134 fp=0x4000054f90 sp=0x4000054f10 pc=0xd9504
testing.(*B).run1.func1()
  /usr/local/go/src/testing/benchmark.go:233 +0x54 fp=0x4000054fd0 sp=0x4000054f90 pc=0xd9ab4
runtime.goexit()
  /usr/local/go/src/runtime/asm_arm64.s:1270 +0x4 fp=0x4000054fd0 sp=0x4000054fd0 pc=0x78814
created by testing.(*B).run1
  /usr/local/go/src/testing/benchmark.go:226 +0x90

goroutine 1 [chan receive]:
testing.(*B).run1(0x400014c900)
  /usr/local/go/src/testing/benchmark.go:235 +0xa0
testing.(*B).Run(0x400014c240, {0x37d10a?, 0x4000105b28?}, 0x389430)
  /usr/local/go/src/testing/benchmark.go:676 +0x3d0
testing.runBenchmarks.func1(0x400014c240?)
  /usr/local/go/src/testing/benchmark.go:550 +0x74
testing.(*B).runN(0x400014c240, 0x1)
  /usr/local/go/src/testing/benchmark.go:193 +0x134
testing.runBenchmarks({0x36f47b, 0x9}, 0x6289c0?, {0x5f2660, 0xa2, 0x23540?})
  /usr/local/go/src/testing/benchmark.go:559 +0x3a8
testing.(*M).Run(0x4000014d20)
  /usr/local/go/src/testing/testing.go:1726 +0x6e0
main.main()
  _testmain.go:369 +0x1e8
exit status 2

Updating libraries github.com/json-iterator/go and github.com/wI2L/jettison solves the problem.

codecov-commenter commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 78.51%. Comparing base (5e2ae3f) to head (b11b2cf).

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #508 +/- ## ========================================== - Coverage 78.53% 78.51% -0.02% ========================================== Files 55 55 Lines 16712 16712 ========================================== - Hits 13124 13121 -3 - Misses 2956 2958 +2 - Partials 632 633 +1 ```