We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go version
$ go version go version go1.19.2 linux/amd64
Yes
go env
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/lib/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.19.2" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="x86_64-pc-linux-gnu-gcc" CXX="x86_64-pc-linux-gnu-g++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1032427755=/tmp/go-build -gno-record-gcc-switches"
https://go.dev/play/p/9j5NigpTkVg
package main import ( "sync" "golang.org/x/text/collate" "golang.org/x/text/language" ) var enUsIgnoreCase = collate.New(language.AmericanEnglish, collate.IgnoreCase) func main() { const N = 10_000 wg := new(sync.WaitGroup) wg.Add(N) for i := 0; i < N; i++ { go func() { defer wg.Done(); enUsIgnoreCase.CompareString("foobar", "baz") }() } wg.Wait() }
Nothing (no error).
panic: runtime error: index out of range [-1] goroutine 1349 [running]: golang.org/x/text/internal/colltab.(*Iter).Next(0xc000116860) /tmp/gopath1836550904/pkg/mod/golang.org/x/[email protected]/internal/colltab/iter.go:104 +0x239 golang.org/x/text/collate.(*iter).nextPrimary(0xc000116060) /tmp/gopath1836550904/pkg/mod/golang.org/x/[email protected]/collate/collate.go:254 +0x35 golang.org/x/text/collate.compareLevel(0x4d4228, 0xc000116060, 0xc0001168d0) /tmp/gopath1836550904/pkg/mod/golang.org/x/[email protected]/collate/collate.go:143 +0x54 golang.org/x/text/collate.(*Collator).compare(0xc000116000) /tmp/gopath1836550904/pkg/mod/golang.org/x/[email protected]/collate/collate.go:162 +0x45 golang.org/x/text/collate.(*Collator).CompareString(0xc000116000, {0x4c79d4, 0x6}, {0x4c756f, 0x3}) /tmp/gopath1836550904/pkg/mod/golang.org/x/[email protected]/collate/collate.go:126 +0x145 main.main.func1() /tmp/sandbox4270487653/prog.go:17 +0x77 created by main.main /tmp/sandbox4270487653/prog.go:17 +0x3d Program exited.
The text was updated successfully, but these errors were encountered:
I see no indication in the collate package documentation that it is not threadsafe, so I assumed I could define the collation as a package variable.
Sorry, something went wrong.
In general, unless explicitly documented to be safe for concurrent use (eg text/template.Template.Execute, that is not a safe assumption to make.
see also #3611 (comment)
No branches or pull requests
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/9j5NigpTkVg
What did you expect to see?
Nothing (no error).
What did you see instead?
The text was updated successfully, but these errors were encountered: