mapslice-json icon indicating copy to clipboard operation
mapslice-json copied to clipboard

fix DATA RACE when it calls nextIndex()

Open t2y opened this issue 11 months ago • 0 comments

I found a DATA RACE error when I wrote some test code using mapslice-json.

You can reproduce quickly by invoking a test function included in this PR.

$ go test -race ./.... -run TestConcurrentUnmarshal
==================
WARNING: DATA RACE
Read at 0x0000007e6a28 by goroutine 10:
  github.com/ake-persson/mapslice-json.nextIndex()
      path/to/mapslice-json/mapslice.go:26 +0x127
  github.com/ake-persson/mapslice-json.(*MapItem).UnmarshalJSON()
      path/to/mapslice-json/mapslice.go:76 +0x113
  encoding/json.(*decodeState).literalStore()
      /usr/local/go1.22.0/src/encoding/json/decode.go:854 +0x394a
...

Also, I updated go version and MakeFile.

t2y avatar Mar 08 '24 08:03 t2y