-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed as not planned
Labels
Milestone
Description
Go version
1.22.0
Output of go env
in your module/workspace:
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/jonhall/.cache/go-build'
GOENV='/home/jonhall/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/jonhall/go/pkg/mod'
GONOPROXY='gitlab.com/FlashbackSRS/priv,gitlab.com/flimzy/hacker-portfolio'
GONOSUMDB='gitlab.com/FlashbackSRS/priv,gitlab.com/flimzy/hacker-portfolio'
GOOS='linux'
GOPATH='/home/jonhall/go'
GOPRIVATE='gitlab.com/FlashbackSRS/priv,gitlab.com/flimzy/hacker-portfolio'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='/usr/bin/gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/jonhall/src/kivik/kivik/x/sqlite/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build697470253=/tmp/go-build -gno-record-gcc-switches'
What did you do?
go test -race
with this file:
package main
import (
"testing"
"golang.org/x/text/collate"
"golang.org/x/text/language"
)
func TestCollate(t *testing.T) {
collator := collate.New(language.Und)
go collator.CompareString("a", "b")
go collator.CompareString("a", "b")
}
And my go.mod
:
module github.com/flimzy/test
go 1.22.0
require golang.org/x/text v0.15.0
What did you see happen?
A data race:
$ go test -race .
PASS
==================
WARNING: DATA RACE
Write at 0x00c0001fa8b0 by goroutine 8:
golang.org/x/text/internal/colltab.(*Iter).SetInputString()
/home/jonhall/go/pkg/mod/golang.org/x/text@v0.15.0/internal/colltab/iter.go:67 +0x52
golang.org/x/text/collate.(*Collator).CompareString()
/home/jonhall/go/pkg/mod/golang.org/x/text@v0.15.0/collate/collate.go:124 +0x4a
github.com/flimzy/test.TestCollate.gowrap1()
/home/jonhall/src/test/test_test.go:13 +0x49
<snip>
What did you expect to see?
I was not expecting a race.
While it's perhaps reasonable to mutate internal state whe calling a comparison function, it's not at all obvious that it would or should, at least not to someone like me who is unfamiliar with the mechanics of collation logic.
I would like to request that, at minimum, the package is documented to not be concurrency-safe.
As a bonus, making it concurrency-safe would be even better, if feasible.