A single collator instance is NOT safe for concurrent use. The buffers are only used to store the keys, but a Collator has some scratch buffers that are used to avoid allocation.
I suggest using a new Collator per goroutine, if possible. On Sun, Jun 12, 2016 at 7:32 PM, 'Sugu Sougoumarane' via golang-nuts < golang-nuts@googlegroups.com> wrote: > This issue was reported for vitess: > https://github.com/youtube/vitess/issues/1787 > > I'm using a single Collator to build keys, and it gets called > concurrently. I assumed it was fair use because the Key function accepts a > separate buffer for it. > Should I instead build a new Collator for every call? Or should I use a > mutex before calling Key? > > The call stack in question (pasted from issue): > > > > github.com/youtube/vitess/vendor/golang.org/x/text/internal/colltab.(Iter).Next(0xc820134c60, > 0xc820067001) > > /Users/yuqing/projects/GoHome/src/ > github.com/youtube/vitess/vendor/golang.org/x/text/internal/colltab/iter.go:105 > +0x2f8 > > > github.com/youtube/vitess/vendor/golang.org/x/text/collate.(Collator).getColElems(0xc820134400, > 0xc82044a700, 0x7, 0x12, 0x0, 0x0, 0x0) > > /Users/yuqing/projects/GoHome/src/ > github.com/youtube/vitess/vendor/golang.org/x/text/collate/collate.go:223 > +0xf5 > > > github.com/youtube/vitess/vendor/golang.org/x/text/collate.(Collator).Key(0xc820134400, > 0xc820a7e400, 0xc82044a700, 0x7, 0x12, 0x0, 0x0, 0x0) > > /Users/yuqing/projects/GoHome/src/ > github.com/youtube/vitess/vendor/golang.org/x/text/collate/collate.go:200 > +0xbf > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.