wI2L / jettison

Highly configurable, fast JSON encoder for Go
https://pkg.go.dev/github.com/wI2L/jettison
MIT License
174 stars 13 forks source link

Panic when marshaling maps in Go 1.18 #6

Closed flusflas closed 2 years ago

flusflas commented 2 years ago

Hi, I just updated to Go 1.18 and jettison (v0.7.3) started failing when marshaling maps. This code:

package main

import "github.com/wI2L/jettison"

func main() {
    jettison.Marshal(map[string]interface{}{
        "test": 123,
    })
}

will fail using Go 1.18 with this stacktrace:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x100 pc=0x460e05]

goroutine 1 [running]:
runtime.throw({0x4ca188?, 0xc00011c078?})
    /home/flusflas/.gvm/gos/go1.18/src/runtime/panic.go:992 +0x71 fp=0xc00008da38 sp=0xc00008da08 pc=0x430bd1
runtime.sigpanic()
    /home/flusflas/.gvm/gos/go1.18/src/runtime/signal_unix.go:802 +0x3a9 fp=0xc00008da88 sp=0xc00008da38 pc=0x444789
sync.(*Pool).Get(0x56b100)
    /home/flusflas/.gvm/gos/go1.18/src/sync/pool.go:129 +0x25 fp=0xc00008dac0 sp=0xc00008da88 pc=0x460e05
github.com/wI2L/jettison.encodeSortedMap(0x56b0c0, {0xc000138000, 0x1, 0x1000}, {{0x4e5730, 0xc00012c028}, {0x4c8fa0, 0x23}, 0x5, 0x0, ...}, ...)
    /home/flusflas/go/pkg/mod/github.com/w!i2!l/jettison@v0.7.3/encode.go:415 +0x7a fp=0xc00008dc00 sp=0xc00008dac0 pc=0x49a13a
github.com/wI2L/jettison.encodeMap(0x2?, {0xc000138000, 0x0, 0x1000}, {{0x4e5730, 0xc00012c028}, {0x4c8fa0, 0x23}, 0x5, 0x0, ...}, ...)
    /home/flusflas/go/pkg/mod/github.com/w!i2!l/jettison@v0.7.3/encode.go:364 +0x337 fp=0xc00008dce0 sp=0xc00008dc00 pc=0x499cd7
github.com/wI2L/jettison.newMapInstr.func1(0x56b000?, {0xc000138000?, 0xc00010c2b0?, 0xc000138000?}, {{0x4e5730, 0xc00012c028}, {0x4c8fa0, 0x23}, 0x5, 0x0, ...})
    /home/flusflas/go/pkg/mod/github.com/w!i2!l/jettison@v0.7.3/instruction.go:400 +0x72 fp=0xc00008dd70 sp=0xc00008dce0 pc=0x49ff52
github.com/wI2L/jettison.wrapInlineInstr.func1(0xc00010e150, {0xc000138000?, 0x203000?, 0x0?}, {{0x4e5730, 0xc00012c028}, {0x4c8fa0, 0x23}, 0x5, 0x0, ...})
    /home/flusflas/go/pkg/mod/github.com/w!i2!l/jettison@v0.7.3/instruction.go:406 +0x65 fp=0xc00008dde0 sp=0xc00008dd70 pc=0x4a0165
github.com/wI2L/jettison.marshalJSON({0x4b2a80?, 0xc00010e150?}, {{0x4e5730, 0xc00012c028}, {0x4c8fa0, 0x23}, 0x5, 0x0, 0x0, 0x0})
    /home/flusflas/go/pkg/mod/github.com/w!i2!l/jettison@v0.7.3/json.go:167 +0xd9 fp=0xc00008dea8 sp=0xc00008dde0 pc=0x4a0eb9
github.com/wI2L/jettison.Marshal({0x4b2a80?, 0xc00010e150?})
    /home/flusflas/go/pkg/mod/github.com/w!i2!l/jettison@v0.7.3/json.go:115 +0xbf fp=0xc00008df48 sp=0xc00008dea8 pc=0x4a0d7f
main.main()
    /home/flusflas/main/main.go:6 +0x7a fp=0xc00008df80 sp=0xc00008df48 pc=0x4a601a

I tried to look for any reported bug with pools in Go 1.18, but I didn't find anything, and I feel a little lost here.

wI2L commented 2 years ago

The runtime map iterator representation might have changed in 1.18. I'll have a look this week.

wI2L commented 2 years ago

Found the issue, it's related to a change in this PR: https://github.com/golang/go/commit/1b2d794ca3ba60c2dbc958a271662784a7122739 Which only affect go.18, and further versions to come.

I'll release a fix in a new version shortly.

flusflas commented 2 years ago

Wow, it was quick. Thanks!