n10v / id3v2

🎵 ID3 decoding and encoding library for Go
https://pkg.go.dev/github.com/bogem/id3v2/v2
MIT License
339 stars 53 forks source link

Attempt to fix parallel decoding #74

Closed drgolem closed 2 years ago

drgolem commented 2 years ago

Added unit test TestDecodeTextParallel to demo an issue of decoding in multiple goroutines. run test:

go test -race ./...

result:

WARNING: DATA RACE
Write at 0x00c0000aa0ee by goroutine 36:
  golang.org/x/text/encoding/unicode.(*utf16Decoder).Reset()
      /Users/val/goLand/pkg/mod/golang.org/x/text@v0.3.2/encoding/unicode/unicode.go:286 +0x57
  golang.org/x/text/encoding.(*Decoder).Reset()
      <autogenerated>:1 +0x49
  golang.org/x/text/transform.doAppend()
      /Users/val/goLand/pkg/mod/golang.org/x/text@v0.3.2/transform/transform.go:689 +0x90
  golang.org/x/text/transform.Bytes()
      /Users/val/goLand/pkg/mod/golang.org/x/text@v0.3.2/transform/transform.go:674 +0x8f
  golang.org/x/text/encoding.(*Decoder).Bytes()
      /Users/val/goLand/pkg/mod/golang.org/x/text@v0.3.2/encoding/encoding.go:57 +0x30
  github.com/bogem/id3v2/v2.decodeText()

this can be fixed by

    //result, err := fromXEncoding.Decoder().Bytes(src)
    result, err := fromXEncoding.encoding.NewDecoder().Bytes(src)

This is just a proposal, please suggest better fix.